Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 9f379cf

Browse files
committed
feat: makes the admin group a list of groups
this will allow multiple groups to be granted access to application-level admin
1 parent 481bb81 commit 9f379cf

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

cerberus-web/src/main/java/com/nike/cerberus/service/AuthenticationService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class AuthenticationService {
9292
private final KmsService kmsService;
9393
private final KmsClientFactory kmsClientFactory;
9494
private final ObjectMapper objectMapper;
95-
private final String adminGroup;
95+
private final List<String> adminGroups;
9696
private final DateTimeSupplier dateTimeSupplier;
9797
private final AwsIamRoleArnParser awsIamRoleArnParser;
9898
private final AuthTokenService authTokenService;
@@ -116,7 +116,7 @@ public AuthenticationService(
116116
KmsClientFactory kmsClientFactory,
117117
ObjectMapper objectMapper,
118118
@Value("${cerberus.admin.roles:#{null}}") String adminRoleArns,
119-
@Value("${cerberus.admin.group}") String adminGroup,
119+
@Value("#{'${cerberus.admin.groups}'.split(',')}") List<String> adminGroups,
120120
@Value("${cerberus.auth.user.token.maxRefreshCount:#{0}}") int maxTokenRefreshCount,
121121
DateTimeSupplier dateTimeSupplier,
122122
AwsIamRoleArnParser awsIamRoleArnParser,
@@ -133,7 +133,7 @@ public AuthenticationService(
133133
this.kmsClientFactory = kmsClientFactory;
134134
this.objectMapper = objectMapper;
135135
this.adminRoleArns = adminRoleArns;
136-
this.adminGroup = adminGroup;
136+
this.adminGroups = adminGroups;
137137
this.dateTimeSupplier = dateTimeSupplier;
138138
this.awsIamRoleArnParser = awsIamRoleArnParser;
139139
this.maxTokenRefreshCount = maxTokenRefreshCount;
@@ -525,8 +525,11 @@ private AuthTokenResponse generateToken(
525525
meta.put(CerberusPrincipal.METADATA_KEY_USERNAME, username);
526526

527527
boolean isAdmin = false;
528-
if (userGroups.contains(this.adminGroup)) {
529-
isAdmin = true;
528+
for (String group : this.adminGroups) {
529+
if (userGroups.contains(group)) {
530+
isAdmin = true;
531+
break;
532+
}
530533
}
531534
meta.put(METADATA_KEY_IS_ADMIN, String.valueOf(isAdmin));
532535
meta.put(CerberusPrincipal.METADATA_KEY_GROUPS, StringUtils.join(userGroups, ','));

cerberus-web/src/main/resources/cerberus.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ cerberus:
5757
environmentName: TODO
5858
admin:
5959
# These are aws principal that you want to allow to use the admin API
60+
# comma-separated string
6061
roles: ~
61-
# The user group that the Cerberus operators belong to, this unlocks admin API perms
62-
group: ~
62+
# The user groups that the Cerberus operators belong to, this unlocks admin API perms
63+
# comma-separated string
64+
groups: ~
6365

6466
encryption:
6567
# comma delimited list of the CMKs for a KMS key that the iam role that Cerberus runs as has access to.

cerberus-web/src/test/java/com/nike/cerberus/service/AuthenticationServiceTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import com.fasterxml.jackson.core.JsonProcessingException;
3232
import com.fasterxml.jackson.databind.ObjectMapper;
33+
import com.google.common.collect.Lists;
3334
import com.nike.backstopper.exception.ApiException;
3435
import com.nike.cerberus.PrincipalType;
3536
import com.nike.cerberus.auth.connector.AuthConnector;
@@ -96,7 +97,7 @@ public void setup() {
9697
kmsClientFactory,
9798
objectMapper,
9899
"foo",
99-
"groups",
100+
Lists.newArrayList("group1", "group2", "group3"),
100101
MAX_LIMIT,
101102
dateTimeSupplier,
102103
awsIamRoleArnParser,

0 commit comments

Comments
 (0)