Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sia: set service cert and key in role option #2558

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions libs/go/sia/aws/options/data/sia_with_roles
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "1.0.0",
"service": "api",
"accounts": [
{
"domain": "athenz",
"user": "nobody",
"account": "123456789012",
"roles": {
"sports:role.readers": {
},
"sports:role.writers": {
}
}
}
]
}
56 changes: 56 additions & 0 deletions libs/go/sia/aws/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,62 @@ func TestOptionsWithGenerateRoleKeyConfig(t *testing.T) {
assert.Equal(t, 2, count)
}

func TestOptionsWithRolesConfig(t *testing.T) {
cfg, cfgAccount, _ := getConfig("data/sia_generate_role_key", "-service", "http://localhost:80", false, "us-west-2")
opts, e := setOptions(cfg, cfgAccount, nil, "/tmp", "1.0.0")
require.Nilf(t, e, "error should not be thrown, error: %v", e)
assert.True(t, opts.GenerateRoleKey)
assert.Equal(t, 2, len(opts.Roles))
count := 0
for _, role := range opts.Roles {
switch role.Name {
case "sports:role.readers":
assert.Equal(t, 0440, role.FileMode)
assert.Equal(t, "/tmp/keys/sports:role.readers.key.pem", role.RoleKeyFilename)
assert.Equal(t, "/tmp/certs/sports:role.readers.cert.pem", role.RoleCertFilename)
assert.Equal(t, "/tmp/keys/athenz.api.key.pem", role.SvcKeyFilename)
assert.Equal(t, "/tmp/certs/athenz.api.cert.pem", role.SvcCertFilename)
count += 1
case "sports:role.writers":
assert.Equal(t, 0440, role.FileMode)
assert.Equal(t, "/tmp/keys/sports:role.writers.key.pem", role.RoleKeyFilename)
assert.Equal(t, "/tmp/certs/sports:role.writers.cert.pem", role.RoleCertFilename)
assert.Equal(t, "/tmp/keys/athenz.api.key.pem", role.SvcKeyFilename)
assert.Equal(t, "/tmp/certs/athenz.api.cert.pem", role.SvcCertFilename)
count += 1
}
}
assert.Equal(t, 2, count)
}

func TestOptionsWithRoles(t *testing.T) {
cfg, cfgAccount, _ := getConfig("data/sia_with_roles", "-service", "http://localhost:80", false, "us-west-2")
opts, e := setOptions(cfg, cfgAccount, nil, "/tmp", "1.0.0")
require.Nilf(t, e, "error should not be thrown, error: %v", e)
assert.False(t, opts.GenerateRoleKey)
assert.Equal(t, 2, len(opts.Roles))
count := 0
for _, role := range opts.Roles {
switch role.Name {
case "sports:role.readers":
assert.Equal(t, 0440, role.FileMode)
assert.Equal(t, "", role.RoleKeyFilename)
assert.Equal(t, "/tmp/certs/sports:role.readers.cert.pem", role.RoleCertFilename)
assert.Equal(t, "/tmp/keys/athenz.api.key.pem", role.SvcKeyFilename)
assert.Equal(t, "/tmp/certs/athenz.api.cert.pem", role.SvcCertFilename)
count += 1
case "sports:role.writers":
assert.Equal(t, 0440, role.FileMode)
assert.Equal(t, "", role.RoleKeyFilename)
assert.Equal(t, "/tmp/certs/sports:role.writers.cert.pem", role.RoleCertFilename)
assert.Equal(t, "/tmp/keys/athenz.api.key.pem", role.SvcKeyFilename)
assert.Equal(t, "/tmp/certs/athenz.api.cert.pem", role.SvcCertFilename)
count += 1
}
}
assert.Equal(t, 2, count)
}

func TestOptionsWithRotateKeyConfig(t *testing.T) {
cfg, cfgAccount, _ := getConfig("data/sia_rotate_key", "-service", "http://localhost:80", false, "us-west-2")
opts, e := setOptions(cfg, cfgAccount, nil, "/tmp", "1.0.0")
Expand Down
19 changes: 19 additions & 0 deletions libs/go/sia/options/data/sia_with_roles
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "1.0.0",
"service": "api",
"domain": "athenz",
"user": "nobody",
"accounts": [
{
"domain": "athenz",
"user": "nobody",
"account": "123456789012"
}
],
"roles": {
"sports:role.readers": {
},
"sports:role.writers": {
}
}
}
4 changes: 2 additions & 2 deletions libs/go/sia/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,8 @@ func setOptions(config *Config, account *ConfigAccount, profileConfig *AccessPro
role := Role{
Name: name,
Service: roleService.Name,
SvcKeyFilename: roleService.KeyFilename,
SvcCertFilename: roleService.CertFilename,
SvcKeyFilename: util.GetSvcKeyFileName(keyDir, roleService.KeyFilename, account.Domain, roleService.Name),
SvcCertFilename: util.GetSvcCertFileName(certDir, roleService.CertFilename, account.Domain, roleService.Name),
RoleCertFilename: util.GetRoleCertFileName(certDir, r.Filename, name),
RoleKeyFilename: util.GetRoleKeyFileName(keyDir, r.Filename, name, generateRoleKey),
ExpiryTime: r.ExpiryTime,
Expand Down
30 changes: 30 additions & 0 deletions libs/go/sia/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,39 @@ func TestOptionsWithGenerateRoleKeyConfig(t *testing.T) {
switch role.Name {
case "sports:role.readers":
assert.Equal(t, 0440, role.FileMode)
assert.Equal(t, "/tmp/keys/sports:role.readers.key.pem", role.RoleKeyFilename)
count += 1
case "sports:role.writers":
assert.Equal(t, 0440, role.FileMode)
assert.Equal(t, "/tmp/keys/sports:role.writers.key.pem", role.RoleKeyFilename)
count += 1
}
}
assert.Equal(t, 2, count)
}

func TestOptionsWithRoles(t *testing.T) {
cfg, cfgAccount, _ := getConfig("data/sia_with_roles", "-service", "http://localhost:80", false, "us-west-2")
opts, e := setOptions(cfg, cfgAccount, nil, "/tmp", "1.0.0")
require.Nilf(t, e, "error should not be thrown, error: %v", e)
assert.False(t, opts.GenerateRoleKey)
assert.Equal(t, 2, len(opts.Roles))
count := 0
for _, role := range opts.Roles {
switch role.Name {
case "sports:role.readers":
assert.Equal(t, 0440, role.FileMode)
assert.Equal(t, "", role.RoleKeyFilename)
assert.Equal(t, "/tmp/certs/sports:role.readers.cert.pem", role.RoleCertFilename)
assert.Equal(t, "/tmp/keys/athenz.api.key.pem", role.SvcKeyFilename)
assert.Equal(t, "/tmp/certs/athenz.api.cert.pem", role.SvcCertFilename)
count += 1
case "sports:role.writers":
assert.Equal(t, 0440, role.FileMode)
assert.Equal(t, "", role.RoleKeyFilename)
assert.Equal(t, "/tmp/certs/sports:role.writers.cert.pem", role.RoleCertFilename)
assert.Equal(t, "/tmp/keys/athenz.api.key.pem", role.SvcKeyFilename)
assert.Equal(t, "/tmp/certs/athenz.api.cert.pem", role.SvcCertFilename)
count += 1
}
}
Expand Down