Skip to content

Commit b700ffb

Browse files
authored
feat(keyless): expose signing service though GRPC (chainloop-dev#861)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent 59bbbf2 commit b700ffb

File tree

12 files changed

+477
-155
lines changed

12 files changed

+477
-155
lines changed

app/controlplane/cmd/main.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222

2323
"github.com/bufbuild/protovalidate-go"
2424
"github.com/getsentry/sentry-go"
25+
"github.com/sigstore/fulcio/pkg/ca"
26+
"github.com/sigstore/fulcio/pkg/ca/fileca"
2527
flag "github.com/spf13/pflag"
2628

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

130-
app, cleanup, err := wireApp(&bc, credsWriter, logger, availablePlugins)
132+
ctx, cancel := context.WithCancel(context.Background())
133+
defer cancel()
134+
135+
ca, err := newSigningCA(ctx, bc.GetCertificateAuthority(), logger)
136+
if err != nil {
137+
panic(err)
138+
}
139+
app, cleanup, err := wireApp(&bc, credsWriter, logger, availablePlugins, ca)
131140
if err != nil {
132141
panic(err)
133142
}
134143
defer cleanup()
135144

136-
ctx, cancel := context.WithCancel(context.Background())
137-
defer cancel()
138-
139145
// Run an expiration job every minute that expires unfinished runs older than 1 hour
140146
// TODO: Make it configurable from the application config
141147
app.runsExpirer.Run(ctx, &biz.WorkflowRunExpirerOpts{CheckInterval: 1 * time.Minute, ExpirationWindow: 1 * time.Hour})
@@ -218,3 +224,16 @@ func initSentry(c *conf.Bootstrap, logger log.Logger) (cleanupFunc func(), err e
218224
func newProtoValidator() (*protovalidate.Validator, error) {
219225
return protovalidate.New()
220226
}
227+
228+
func newSigningCA(_ context.Context, ca *conf.CA, logger log.Logger) (ca.CertificateAuthority, error) {
229+
// File
230+
if ca.GetFileCa() != nil {
231+
fileCa := ca.GetFileCa()
232+
_ = logger.Log(log.LevelInfo, "msg", "Keyless: File CA configured")
233+
return fileca.NewFileCA(fileCa.GetCertPath(), fileCa.GetKeyPath(), fileCa.GetKeyPass(), false)
234+
}
235+
236+
// No CA configured, keyless will be deactivated.
237+
_ = logger.Log(log.LevelInfo, "msg", "Keyless Signing NOT configured")
238+
return nil, nil
239+
}

app/controlplane/cmd/wire.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ import (
3333
"github.com/chainloop-dev/chainloop/internal/credentials"
3434
"github.com/go-kratos/kratos/v2/log"
3535
"github.com/google/wire"
36+
"github.com/sigstore/fulcio/pkg/ca"
3637
)
3738

38-
func wireApp(*conf.Bootstrap, credentials.ReaderWriter, log.Logger, sdk.AvailablePlugins) (*app, func(), error) {
39+
func wireApp(*conf.Bootstrap, credentials.ReaderWriter, log.Logger, sdk.AvailablePlugins, ca.CertificateAuthority) (*app, func(), error) {
3940
panic(
4041
wire.Build(
4142
wire.Bind(new(credentials.Reader), new(credentials.ReaderWriter)),

app/controlplane/cmd/wire_gen.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/configs/config.devel.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ server:
1313
# We have some slow operations such as verifying an OCI registry
1414
timeout: 10s
1515

16+
certificate_authority:
17+
file_ca:
18+
cert_path: "../../devel/devkeys/ca.pub"
19+
key_path: "../../devel/devkeys/ca.pem"
20+
key_pass: chainloop
21+
1622
# Directory where the plugins are located
1723
# NOTE: plugins have the form of chainloop-plugin-<name>
1824
plugins_dir: "./plugins/bin"

app/controlplane/internal/biz/signing.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func NewChainloopSigningUseCase(ca ca.CertificateAuthority) *SigningUseCase {
3838

3939
// CreateSigningCert signs a certificate request with a configured CA, and returns the full certificate chain
4040
func (s *SigningUseCase) CreateSigningCert(ctx context.Context, orgID string, csrRaw []byte) ([]string, error) {
41+
if s.CA == nil {
42+
return nil, errors.New("CA not initialized")
43+
}
44+
4145
var publicKey crypto.PublicKey
4246

4347
if len(csrRaw) == 0 {

0 commit comments

Comments
 (0)