-
Notifications
You must be signed in to change notification settings - Fork 460
Add GCS principal attribution to vended credentials via Workload Identity Federation #4707
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
Open
obelix74
wants to merge
6
commits into
apache:main
Choose a base branch
from
obelix74:gcs-principal-attribution-wif
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
df1381e
Add GCS principal attribution to vended credentials via Workload Iden…
4533739
Merge branch 'main' into gcs-principal-attribution-wif
35c1316
Add com.auth0:java-jwt license entry to admin distribution LICENSE
97ba877
Update config docs site for GCS principal attribution flags
5124269
CI: retrigger after runner out-of-disk-space failure
b8eb8fa
GCS attribution: pre-compute params at cache key build time
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
89 changes: 89 additions & 0 deletions
89
...-core/src/main/java/org/apache/polaris/core/storage/gcp/GcpAttributionSubjectBuilder.java
This file contains hidden or 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,89 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 org.apache.polaris.core.storage.gcp; | ||
|
|
||
| /** | ||
| * Builds the {@code sub} claim for GCS principal-attribution JWTs as {@code <realm>/<principal>}, | ||
| * within GCP's 127-character {@code google.subject} limit. | ||
| * | ||
| * <p>The character budget mirrors the AWS session-name builder: one character is reserved for the | ||
| * separator, then each field receives an equal share of the remainder, and budget unused by a short | ||
| * field flows to the other. ISO control characters and the {@code /} separator are stripped from | ||
| * each field so the subject stays unambiguously parseable, and the {@code unknown} placeholder | ||
| * substitutes null/empty fields so the subject shape stays stable. | ||
| */ | ||
| public final class GcpAttributionSubjectBuilder { | ||
|
|
||
| /** GCP limit for the {@code google.subject} attribute of a federated identity. */ | ||
| public static final int MAX_SUBJECT_LENGTH = 127; | ||
|
|
||
| static final String SEPARATOR = "/"; | ||
|
|
||
| static final String VALUE_UNKNOWN = "unknown"; | ||
|
|
||
| private GcpAttributionSubjectBuilder() {} | ||
|
|
||
| /** | ||
| * Builds the attribution subject {@code <realm>/<principal>}, guaranteed to be at most {@value | ||
| * #MAX_SUBJECT_LENGTH} characters. | ||
| * | ||
| * @param realm the realm identifier (gets first-half budget priority) | ||
| * @param principalName the Polaris principal name | ||
| * @return the subject string | ||
| */ | ||
| public static String buildSubject(String realm, String principalName) { | ||
| String cleanRealm = sanitize(realm); | ||
| String cleanPrincipal = sanitize(principalName); | ||
|
|
||
| int budget = MAX_SUBJECT_LENGTH - SEPARATOR.length(); | ||
| int remaining = budget; | ||
|
|
||
| int realmAlloc = remaining / 2; | ||
| int realmUsed = Math.min(cleanRealm.length(), realmAlloc); | ||
| remaining -= realmUsed; | ||
|
|
||
| int principalUsed = Math.min(cleanPrincipal.length(), remaining); | ||
| remaining -= principalUsed; | ||
|
|
||
| // Carry-forward: if the principal left budget unused, the realm may take more than its | ||
| // initial half-share. | ||
| int realmFinal = Math.min(cleanRealm.length(), realmUsed + remaining); | ||
|
|
||
| return cleanRealm.substring(0, realmFinal) | ||
| + SEPARATOR | ||
| + cleanPrincipal.substring(0, principalUsed); | ||
| } | ||
|
|
||
| private static String sanitize(String value) { | ||
| if (value == null || value.isEmpty()) { | ||
| return VALUE_UNKNOWN; | ||
| } | ||
| StringBuilder cleaned = new StringBuilder(value.length()); | ||
| for (int i = 0; i < value.length(); i++) { | ||
| char c = value.charAt(i); | ||
| // Drop control chars and the separator itself so the subject stays unambiguously | ||
| // <realm>/<principal>: a value containing '/' would otherwise let an audit-log consumer | ||
| // mis-split it (e.g. principal "a/b" read as realm "a", principal "b"). | ||
| if (!Character.isISOControl(c) && c != '/') { | ||
| cleaned.append(c); | ||
| } | ||
| } | ||
| return cleaned.length() == 0 ? VALUE_UNKNOWN : cleaned.toString(); | ||
| } | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will probably work correctly given that
realm IDis part of the cache key, but conceptually, I think it would be nicer to evaluate these parameters at cache key build time (i.e. around line 185) and just use the values here.The cache key is meant to be a "rich" object, so it should be fine to add new data as another (immutable) sub-object, that is if we want to avoid having too many properties at the same level (just an aesthetic concern).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.