Skip to content

Commit bb1159c

Browse files
authored
chore(controlplane): Allow to setup NATS token based authentication (#1944)
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
1 parent 720cc8a commit bb1159c

File tree

7 files changed

+231
-178
lines changed

7 files changed

+231
-178
lines changed

app/controlplane/cmd/main.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,17 @@ func newNatsConnection(c *conf.Bootstrap_NatsServer) (*nats.Conn, error) {
189189
return nil, nil
190190
}
191191

192-
nc, err := nats.Connect(uri)
192+
var opts []nats.Option
193+
if c.GetAuthentication() != nil {
194+
switch c.GetAuthentication().(type) {
195+
case *conf.Bootstrap_NatsServer_Token:
196+
opts = append(opts, nats.Token(c.GetToken()))
197+
default:
198+
return nil, fmt.Errorf("unsupported nats authentication type: %T", c.GetAuthentication())
199+
}
200+
}
201+
202+
nc, err := nats.Connect(uri, opts...)
193203
if err != nil {
194204
return nil, fmt.Errorf("failed to connect to nats: %w", err)
195205
}

app/controlplane/internal/conf/controlplane/config/v1/conf.pb.go

+209-174
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/internal/conf/controlplane/config/v1/conf.proto

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ message Bootstrap {
9494
message NatsServer {
9595
// Connection URI
9696
string uri = 1 [(buf.validate.field).string.min_len = 1];
97-
// TODO: add authentication options
97+
oneof authentication {
98+
// Token based authentication
99+
string token = 2 [(buf.validate.field).string.min_len = 1];
100+
}
98101
}
99102
}
100103

deployment/chainloop/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Chainloop is an open source software supply chain control plane, a
77

88
type: application
99
# Bump the patch (not minor, not major) version on each change in the Chart Source code
10-
version: 1.208.0
10+
version: 1.208.1
1111
# Do not update appVersion, this is handled automatically by the release process
1212
appVersion: v1.0.0-rc.1
1313

deployment/chainloop/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ chainloop config save \
557557
| `controlplane.nats.enabled` | Enable events publishing through a Nats stream | `false` |
558558
| `controlplane.nats.host` | NATS Host | `""` |
559559
| `controlplane.nats.port` | NATS Port | `4222` |
560+
| `controlplane.nats.token` | NATS Client authentication token | `""` |
560561
| `controlplane.onboarding.name` | Name of the organization to onboard | |
561562
| `controlplane.onboarding.role` | Role of the organization to onboard | |
562563
| `controlplane.prometheus_org_metrics` | List of organizations to expose metrics for using Prometheus | |

deployment/chainloop/templates/controlplane/secret-config.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ stringData:
9898
{{- if and .Values.controlplane.nats.enabled }}
9999
nats_server:
100100
uri: {{ include "controlplane.nats.connection_string" . | quote }}
101+
{{- if ne .Values.controlplane.nats.token "" }}
102+
token: {{ .Values.controlplane.nats.token | quote }}
103+
{{- end }}
101104
{{- end }}
102-
103105
104106
credentials_service: {{- include "chainloop.credentials_service_settings" . | indent 6 }}
105107

deployment/chainloop/values.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,12 @@ controlplane:
181181
## @param controlplane.nats.enabled Enable events publishing through a Nats stream
182182
## @param controlplane.nats.host NATS Host
183183
## @param controlplane.nats.port NATS Port
184+
## @param controlplane.nats.token NATS Client authentication token
184185
nats:
185186
enabled: false
186187
host: ""
187188
port: 4222
189+
token: ""
188190

189191
## @extra controlplane.onboarding.name Name of the organization to onboard
190192
## @extra controlplane.onboarding.role Role of the organization to onboard

0 commit comments

Comments
 (0)