mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(resourceexplorer2): give resource-tag conditions the tags of the resource a request names (#8719)
The generated request resources give Resource Explorer's index and view types the aws:ResourceTag/ key, but ResourceExplorer2Service answered no tags, so a condition on an index's or a view's tags saw none. Its storedTags now reads the index or view stored under the ARN in the account it names, in place, matched on the whole ARN both are kept by; each is an immutable record that tagging replaces. Tag changes now take the service's lock, so two on one resource keep each other's tags.
This commit is contained in:
1 parent
6c18ec745e
commit
7ed62b2597
5 files changed
+79
-5
No files matched your search
@@ -3201,7 +3201,8 @@ floci populates:
|
||||
snapshot schedules, event subscriptions and integrations, SSM for its parameters, documents and associations,
|
||||
EMR for its clusters, CloudFront for every resource it tags, by its ARN, IAM Identity Center for its instances,
|
||||
permission sets, applications and trusted token issuers, OAM for its sinks and links, RAM for its resource shares,
|
||||
and Payment Cryptography for its keys. Tag keys differing only in case are one condition key holding every value.
|
||||
Payment Cryptography for its keys, and Resource Explorer for its indexes and views. Tag keys differing only in
|
||||
case are one condition key holding every value.
|
||||
- EC2 resource keys such as a network interface's `ec2:Vpc`, `ec2:Subnet`, `ec2:AvailabilityZone` and
|
||||
`ec2:NetworkInterfaceID`: for every action on a resource EC2 holds, the members of the resource the
|
||||
key names, an ARN for a key the Service Reference types as one. `resourceKeys` in
|
||||
|
||||
@@ -25,9 +25,9 @@ import java.util.Optional;
|
||||
* the key an alias names and the tags of a key; EMR, for the clusters of its instance groups and a tag call's
|
||||
* resource and the tags of a cluster; IAM Identity Center, for the accounts its permission sets are provisioned to
|
||||
* and the tags of an instance,
|
||||
* a permission set, an application or a trusted token issuer; Resource Explorer, for its default view; OAM and RAM,
|
||||
* for the sinks, invitations and shares of other accounts they act on, OAM for the tags of a sink or a link, and
|
||||
* RAM for the tags of a resource share;
|
||||
* a permission set, an application or a trusted token issuer; Resource Explorer, for its default view and the tags
|
||||
* of an index or a view; OAM and RAM, for the sinks, invitations and shares of other accounts they act on, OAM for
|
||||
* the tags of a sink or a link, and RAM for the tags of a resource share;
|
||||
* Secrets Manager, for the secret a name or an ARN names, random suffix included, and its tags; EventBridge
|
||||
* Scheduler, for its default schedule group and its groups' tags;
|
||||
* CloudFormation, for the stack or the stack set a name names, whose id it minted, and the tags of a stack, a stack set
|
||||
|
||||
+32
-1
@@ -11,6 +11,7 @@ import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.core.resource.ExplorerResource;
|
||||
import io.floci.aws.core.resource.ResourceProvider;
|
||||
import io.floci.aws.core.resource.SupportedResourceType;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
@@ -494,6 +495,35 @@ public class ResourceExplorer2Service implements StoredResourceArns {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags held on the index or view stored under {@code arn}, in the account it names, read in place: both are
|
||||
* kept by their whole ARN, so the ARN is matched whole, and each is an immutable record that tagging replaces.
|
||||
* Empty for an ARN naming neither.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, "resource-explorer-2")) {
|
||||
return Map.of();
|
||||
}
|
||||
String account = AwsArnUtils.parse(arn).accountId();
|
||||
if (account.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<String, String> tags = AccountAwareStorageBackend.readInAccount(indexStore, account, arn)
|
||||
.map(Taggable::tags)
|
||||
.or(() -> AccountAwareStorageBackend.readInAccount(viewStore, account, arn).map(Taggable::tags))
|
||||
.orElse(null);
|
||||
Map<String, String> held = new LinkedHashMap<>();
|
||||
if (tags != null) {
|
||||
tags.forEach((key, value) -> {
|
||||
if (key != null && value != null) {
|
||||
held.put(key, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
return held;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Region's default view, which {@code Search} and {@code ListResources} use for a request naming no view, read
|
||||
* without writing anything, since IAM asks before it decides: the one stored, or, where such a request first
|
||||
@@ -1014,7 +1044,8 @@ public class ResourceExplorer2Service implements StoredResourceArns {
|
||||
mutateTags(arn, current -> tagKeys.forEach(current::remove));
|
||||
}
|
||||
|
||||
private void mutateTags(String arn, Consumer<Map<String, String>> mutation) {
|
||||
/** One tag change at a time, so two on one resource each keep the other's tags. */
|
||||
private synchronized void mutateTags(String arn, Consumer<Map<String, String>> mutation) {
|
||||
StoredTaggable stored = resolveTaggable(arn);
|
||||
Map<String, String> updated = stored.entity().tags() != null
|
||||
? new HashMap<>(stored.entity().tags()) : new HashMap<>();
|
||||
|
||||
@@ -1145,6 +1145,32 @@ class IamRestRouteEnforcementIntegrationTest {
|
||||
return sink;
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@code aws:ResourceTag} condition reads the tags Resource Explorer holds on the view a request names, so an
|
||||
* allow on one team's tag lets the caller read that team's view and not another's.
|
||||
*/
|
||||
@Test
|
||||
void aResourceExplorerResourceTagConditionReadsTheTagsOfTheView() {
|
||||
String tagged = taggedView("data");
|
||||
String other = taggedView("web");
|
||||
String user = user("route-view-tags");
|
||||
|
||||
policy(user, onTeam("Allow", "resource-explorer-2:GetView", "data"));
|
||||
request(user, "resource-explorer-2", "POST", "/GetView", "{\"ViewArn\":\"" + tagged + "\"}").statusCode(200);
|
||||
refused(request(user, "resource-explorer-2", "POST", "/GetView", "{\"ViewArn\":\"" + other + "\"}"),
|
||||
"resource-explorer-2:GetView");
|
||||
}
|
||||
|
||||
/** The ARN of a Resource Explorer view an administrator creates tagged with the team, deleted after the test. */
|
||||
private String taggedView(String team) {
|
||||
String view = adminOf("resource-explorer-2").body("{\"ViewName\":\"route-view-" + suffix()
|
||||
+ "\",\"Tags\":{\"team\":\"" + team + "\"}}").post("/CreateView")
|
||||
.then().statusCode(200).extract().path("View.ViewArn");
|
||||
cleanup.register(() -> adminOf("resource-explorer-2").body("{\"ViewArn\":\"" + view + "\"}")
|
||||
.post("/DeleteView"));
|
||||
return view;
|
||||
}
|
||||
|
||||
@Test
|
||||
void oamIsCheckedOnTheArnItsIdentifiersHold() {
|
||||
String sink = oamSink("{}");
|
||||
|
||||
+16
@@ -47,6 +47,22 @@ class ResourceExplorer2DefaultViewLookupTest {
|
||||
new ObjectMapper(), indexStore, viewStore, defaultViewStore, new InMemoryStorage<>(),
|
||||
new ResourceExplorer2RequestContext());
|
||||
|
||||
/**
|
||||
* IAM's tag lookup reads the tags held on the view the whole ARN names, as tagging leaves them, read in place;
|
||||
* nothing for an ARN naming no stored view or index.
|
||||
*/
|
||||
@Test
|
||||
void storedTagsAreTheTagsOfTheViewTheArnNames() {
|
||||
String view = service.createView(REGION, "tagged", null, null, List.of(), Map.of("team", "data")).viewArn();
|
||||
service.tagResource(view, Map.of("env", "prod"));
|
||||
service.untagResource(view, List.of("team"));
|
||||
|
||||
assertEquals(Map.of("env", "prod"), service.storedTags(view));
|
||||
assertEquals(Map.of(), service.storedTags(VIEWS + "absent/1"));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws:s3:::bucket"));
|
||||
assertTrue(indexStore.scan(key -> true).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theDefaultViewIsReadWithoutProvisioningTheBaseline() {
|
||||
// No index yet: a request naming no view would provision the baseline, whose view's id is not minted yet.
|
||||
|
||||
Reference in new issue
Block a user