Skip to content

Commit

Permalink
feat(keyless): expose signing service though GRPC (chainloop-dev#861)
Browse files Browse the repository at this point in the history
Signed-off-by: Jose I. Paris <[email protected]>
  • Loading branch information
jiparis authored Jun 3, 2024
1 parent 59bbbf2 commit b700ffb
Show file tree
Hide file tree
Showing 12 changed files with 477 additions and 155 deletions.
27 changes: 23 additions & 4 deletions app/controlplane/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (

"github.com/bufbuild/protovalidate-go"
"github.com/getsentry/sentry-go"
"github.com/sigstore/fulcio/pkg/ca"
"github.com/sigstore/fulcio/pkg/ca/fileca"
flag "github.com/spf13/pflag"

"github.com/chainloop-dev/chainloop/app/controlplane/internal/biz"
Expand Down Expand Up @@ -127,15 +129,19 @@ func main() {
// Kill plugins processes on exit
defer availablePlugins.Cleanup()

app, cleanup, err := wireApp(&bc, credsWriter, logger, availablePlugins)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

ca, err := newSigningCA(ctx, bc.GetCertificateAuthority(), logger)
if err != nil {
panic(err)
}
app, cleanup, err := wireApp(&bc, credsWriter, logger, availablePlugins, ca)
if err != nil {
panic(err)
}
defer cleanup()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Run an expiration job every minute that expires unfinished runs older than 1 hour
// TODO: Make it configurable from the application config
app.runsExpirer.Run(ctx, &biz.WorkflowRunExpirerOpts{CheckInterval: 1 * time.Minute, ExpirationWindow: 1 * time.Hour})
Expand Down Expand Up @@ -218,3 +224,16 @@ func initSentry(c *conf.Bootstrap, logger log.Logger) (cleanupFunc func(), err e
func newProtoValidator() (*protovalidate.Validator, error) {
return protovalidate.New()
}

func newSigningCA(_ context.Context, ca *conf.CA, logger log.Logger) (ca.CertificateAuthority, error) {
// File
if ca.GetFileCa() != nil {
fileCa := ca.GetFileCa()
_ = logger.Log(log.LevelInfo, "msg", "Keyless: File CA configured")
return fileca.NewFileCA(fileCa.GetCertPath(), fileCa.GetKeyPath(), fileCa.GetKeyPass(), false)
}

// No CA configured, keyless will be deactivated.
_ = logger.Log(log.LevelInfo, "msg", "Keyless Signing NOT configured")
return nil, nil
}
3 changes: 2 additions & 1 deletion app/controlplane/cmd/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import (
"github.com/chainloop-dev/chainloop/internal/credentials"
"github.com/go-kratos/kratos/v2/log"
"github.com/google/wire"
"github.com/sigstore/fulcio/pkg/ca"
)

func wireApp(*conf.Bootstrap, credentials.ReaderWriter, log.Logger, sdk.AvailablePlugins) (*app, func(), error) {
func wireApp(*conf.Bootstrap, credentials.ReaderWriter, log.Logger, sdk.AvailablePlugins, ca.CertificateAuthority) (*app, func(), error) {
panic(
wire.Build(
wire.Bind(new(credentials.Reader), new(credentials.ReaderWriter)),
Expand Down
6 changes: 5 additions & 1 deletion app/controlplane/cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/controlplane/configs/config.devel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ server:
# We have some slow operations such as verifying an OCI registry
timeout: 10s

certificate_authority:
file_ca:
cert_path: "../../devel/devkeys/ca.pub"
key_path: "../../devel/devkeys/ca.pem"
key_pass: chainloop

# Directory where the plugins are located
# NOTE: plugins have the form of chainloop-plugin-<name>
plugins_dir: "./plugins/bin"
Expand Down
4 changes: 4 additions & 0 deletions app/controlplane/internal/biz/signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func NewChainloopSigningUseCase(ca ca.CertificateAuthority) *SigningUseCase {

// CreateSigningCert signs a certificate request with a configured CA, and returns the full certificate chain
func (s *SigningUseCase) CreateSigningCert(ctx context.Context, orgID string, csrRaw []byte) ([]string, error) {
if s.CA == nil {
return nil, errors.New("CA not initialized")
}

var publicKey crypto.PublicKey

if len(csrRaw) == 0 {
Expand Down
Loading

0 comments on commit b700ffb

Please sign in to comment.