-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(serviceAccounts): enable customization of service account resour…
…ce provider (#668) introduces BaseServiceAccountResourceProvider to capture service account specific access checks"
- Loading branch information
Showing
3 changed files
with
60 additions
and
43 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...rc/main/java/com/netflix/spinnaker/fiat/providers/BaseServiceAccountResourceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.netflix.spinnaker.fiat.providers; | ||
|
||
import com.netflix.spinnaker.fiat.config.FiatRoleConfig; | ||
import com.netflix.spinnaker.fiat.model.resources.Role; | ||
import com.netflix.spinnaker.fiat.model.resources.ServiceAccount; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
import lombok.NonNull; | ||
|
||
public abstract class BaseServiceAccountResourceProvider | ||
extends BaseResourceProvider<ServiceAccount> { | ||
private final FiatRoleConfig fiatRoleConfig; | ||
|
||
public BaseServiceAccountResourceProvider(FiatRoleConfig fiatRoleConfig) { | ||
this.fiatRoleConfig = fiatRoleConfig; | ||
} | ||
|
||
@Override | ||
public Set<ServiceAccount> getAllRestricted(@NonNull Set<Role> roles, boolean isAdmin) | ||
throws ProviderException { | ||
List<String> roleNames = roles.stream().map(Role::getName).collect(Collectors.toList()); | ||
return getAll().stream() | ||
.filter(svcAcct -> !svcAcct.getMemberOf().isEmpty()) | ||
.filter(getServiceAccountPredicate(isAdmin, roleNames)) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
private Predicate<ServiceAccount> getServiceAccountPredicate( | ||
boolean isAdmin, List<String> roleNames) { | ||
if (isAdmin) { | ||
return svcAcct -> true; | ||
} | ||
if (fiatRoleConfig.isOrMode()) { | ||
return svcAcct -> svcAcct.getMemberOf().stream().anyMatch(roleNames::contains); | ||
} else { | ||
return svcAcct -> roleNames.containsAll(svcAcct.getMemberOf()); | ||
} | ||
} | ||
|
||
@Override | ||
public Set<ServiceAccount> getAllUnrestricted() throws ProviderException { | ||
return Collections.emptySet(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters