-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(permission): enables customization of permission sources and agg…
…regation (#481) Adds a `ResourcePermissionSource` - a place to get permissions from, and `ResourcePermissionProvider` - the API for Permissions consumers The default `ResourcePermissionProvider` is a single source ResourcePermissionProvider that reads Permissions from the resource objects, however an AggregatingResourcePermissionProvider is available that will merge all Permissions from all configured ResourcePermissionSources. This can be enabled by setting `auth.permissions.provider.<resource type>: aggregate` There is a `DefaultResourcePermissionConfiguration` that maintains the status quo by providing default ResourcePermissionSources that read Permissions directly off of the objects, but allows opting out of some or all of the default opinions if someone wants to customize, extend, or override any of the default behaviour. Additional improvements: * refactor(fiat-roles): - make DefaultPermissionsResolver immutable - don't return null values from Permissions#get - clean up loadAll * refactor(permissions): Permissions should always have a non null value for all Authorization types Cleans up Permission construction via Permissions.Builder to ensure we populate an immutable collection (empty if unspecified) for all Authorization types when building Permission objects. Redirects empty build() results to a shared Permissions.EMPTY. Fixes up a couple of accidentally non-final constant values. * refactor(permissions): Add Notnull annotations on resource permission provider/source Also moves Authorization.ALL to EnumSet
- Loading branch information
Showing
23 changed files
with
586 additions
and
185 deletions.
There are no files selected for viewing
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
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
35 changes: 35 additions & 0 deletions
35
...n/java/com/netflix/spinnaker/fiat/providers/AccessControlledResourcePermissionSource.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,35 @@ | ||
/* | ||
* Copyright 2019 Google, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.fiat.providers; | ||
|
||
import com.netflix.spinnaker.fiat.model.resources.Permissions; | ||
import com.netflix.spinnaker.fiat.model.resources.Resource; | ||
import java.util.Optional; | ||
import javax.annotation.Nonnull; | ||
|
||
public final class AccessControlledResourcePermissionSource<T extends Resource.AccessControlled> | ||
implements ResourcePermissionSource<T> { | ||
|
||
@Override | ||
@Nonnull | ||
public Permissions getPermissions(@Nonnull T resource) { | ||
return Optional.ofNullable(resource) | ||
.map(Resource.AccessControlled::getPermissions) | ||
.filter(Permissions::isRestricted) | ||
.orElse(Permissions.EMPTY); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...main/java/com/netflix/spinnaker/fiat/providers/AggregatingResourcePermissionProvider.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,56 @@ | ||
/* | ||
* Copyright 2019 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.fiat.providers; | ||
|
||
import com.netflix.spinnaker.fiat.model.Authorization; | ||
import com.netflix.spinnaker.fiat.model.resources.Permissions; | ||
import com.netflix.spinnaker.fiat.model.resources.Resource; | ||
import java.util.List; | ||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* AggregatingResourcePermissionProvider additively combines permissions from all | ||
* ResourcePermissionSources to build a resulting Permission object. | ||
* | ||
* @param <T> the type of Resource for this AggregatingResourcePermissionProvider | ||
*/ | ||
public class AggregatingResourcePermissionProvider<T extends Resource> | ||
implements ResourcePermissionProvider<T> { | ||
|
||
private final List<ResourcePermissionSource<T>> resourcePermissionSources; | ||
|
||
public AggregatingResourcePermissionProvider( | ||
List<ResourcePermissionSource<T>> resourcePermissionSources) { | ||
this.resourcePermissionSources = resourcePermissionSources; | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public Permissions getPermissions(@Nonnull T resource) { | ||
Permissions.Builder builder = new Permissions.Builder(); | ||
for (ResourcePermissionSource<T> source : resourcePermissionSources) { | ||
Permissions permissions = source.getPermissions(resource); | ||
if (permissions.isRestricted()) { | ||
for (Authorization auth : Authorization.values()) { | ||
builder.add(auth, permissions.get(auth)); | ||
} | ||
} | ||
} | ||
|
||
return builder.build(); | ||
} | ||
} |
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
Oops, something went wrong.