Skip to content

Commit 7040174

Browse files
committed
secret management
1 parent 7929fc1 commit 7040174

5 files changed

Lines changed: 39 additions & 5 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.22.0
66

77
require (
88
github.com/Masterminds/sprig/v3 v3.2.3
9-
github.com/cloudentity/acp-client-go v0.0.0-20240618142147-15447bea0396
9+
github.com/cloudentity/acp-client-go v0.0.0-20241209151610-14608290c460
1010
github.com/corvus-ch/zbase32 v1.0.0
1111
github.com/go-json-experiment/json v0.0.0-20240524174822-2d9f40f7385b
1212
github.com/go-openapi/strfmt v0.22.0

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj
77
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
88
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
99
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
10-
github.com/cloudentity/acp-client-go v0.0.0-20240618142147-15447bea0396 h1:nWtlxPLa9os1mp4ASp3R9a+hcQo6hJWv15kYqNXXGyA=
11-
github.com/cloudentity/acp-client-go v0.0.0-20240618142147-15447bea0396/go.mod h1:dTHIsfs5YtDOH2CgeoHFlhfnnU1X+ohn+TIU30WlWQQ=
10+
github.com/cloudentity/acp-client-go v0.0.0-20241209151610-14608290c460 h1:ViagTxoPaC+H0R1QrjnTlXGuqR9PT4VZAI7o8v3c2KU=
11+
github.com/cloudentity/acp-client-go v0.0.0-20241209151610-14608290c460/go.mod h1:dTHIsfs5YtDOH2CgeoHFlhfnnU1X+ohn+TIU30WlWQQ=
1212
github.com/corvus-ch/zbase32 v1.0.0 h1:pDV0qZ1g+HYA8P0PbULsgUg/tZue1FIjsZ7r7h4nZeU=
1313
github.com/corvus-ch/zbase32 v1.0.0/go.mod h1:A7KLRecF1tysURyoqiJBvMJFmt/ccqkRdDTLjlQeVsU=
1414
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
@@ -55,8 +55,6 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
5555
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
5656
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
5757
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
58-
github.com/goccy/go-yaml v1.11.2 h1:joq77SxuyIs9zzxEjgyLBugMQ9NEgTWxXfz2wVqwAaQ=
59-
github.com/goccy/go-yaml v1.11.2/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
6058
github.com/goccy/go-yaml v1.12.0 h1:/1WHjnMsI1dlIBQutrvSMGZRQufVO3asrHfTwfACoPM=
6159
github.com/goccy/go-yaml v1.12.0/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
6260
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=

internal/cac/storage/server_storage.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ func (s *ServerStorage) Write(ctx context.Context, input models.Rfc7396PatchOper
150150
return err
151151
}
152152

153+
if err = writeFiles(data.Secrets,
154+
filepath.Join(workspacePath, "secrets"),
155+
func(id string, it models.TreeSecret) string { return id }); err != nil {
156+
return err
157+
}
158+
153159
slog.Info("Workspace configuration successfully stored", "workspace", workspace, "path", workspacePath)
154160

155161
return nil
@@ -257,6 +263,10 @@ func (s *ServerStorage) Read(ctx context.Context, opts ...api.SourceOpt) (models
257263
return nil, err
258264
}
259265

266+
if err = readFilesToMap(server, "secrets", filepath.Join(path, "secrets")); err != nil {
267+
return nil, err
268+
}
269+
260270
if server, err = utils.FilterPatch(server, options.Filters); err != nil {
261271
return nil, err
262272
}

internal/cac/storage/server_storage_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ func TestStorage(t *testing.T) {
4141
},
4242
assert: func(t *testing.T, path string, bts []byte) {
4343
require.YAMLEq(t, `access_token_ttl: 10m0s
44+
authentication_mechanisms: []
4445
authorization_code_ttl: 0s
46+
scope_claim_formats: []
4547
backchannel_token_delivery_modes_supported: []
4648
backchannel_user_code_parameter_supported: false
4749
cookie_max_age: 0s
@@ -93,6 +95,7 @@ client_id_issued_at: 0
9395
client_name: Demo Portal
9496
client_secret_expires_at: 0
9597
created_at: 0001-01-01T00:00:00.000Z
98+
default_acr_values: []
9699
dpop_bound_access_tokens: false
97100
dynamically_registered: false
98101
grant_types: []
@@ -232,6 +235,7 @@ identifier_case_insensitive: false
232235
mfa_session_ttl: 0s
233236
name: Some Pool
234237
public_registration_allowed: false
238+
second_factor_threshold: 0
235239
system: false`, string(bts))
236240
},
237241
},
@@ -587,10 +591,30 @@ identifier_case_insensitive: false
587591
mfa_session_ttl: 0s
588592
name: Some Pool
589593
public_registration_allowed: false
594+
second_factor_threshold: 0
590595
system: false`, string(bts))
591596
}
592597
},
593598
},
599+
{
600+
desc: "secrets",
601+
data: &models.TreeServer{
602+
Secrets: models.TreeSecrets{
603+
"Some_secret": models.TreeSecret{
604+
CreatedAt: dateTime,
605+
Secret: "test",
606+
},
607+
},
608+
},
609+
files: []string{
610+
"workspaces/demo/secrets/Some_secret.yaml",
611+
},
612+
assert: func(t *testing.T, path string, bts []byte) {
613+
require.YAMLEq(t, `created_at: 2024-01-23T23:19:30.004+01:00
614+
id: Some_secret
615+
secret: test`, string(bts))
616+
},
617+
},
594618
}
595619

596620
for _, tc := range tcs {

internal/cac/storage/tenant_storage_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ id: sms
6060
mechanism: sms`, string(bts))
6161
case "workspaces/demo/server.yaml":
6262
require.YAMLEq(t, `access_token_ttl: 10m0s
63+
authentication_mechanisms: []
6364
authorization_code_ttl: 0s
65+
scope_claim_formats: []
6466
backchannel_token_delivery_modes_supported: []
6567
backchannel_user_code_parameter_supported: false
6668
cookie_max_age: 0s

0 commit comments

Comments
 (0)