Skip to content
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

feat: create impersonated service credentials #499

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

viacheslav-rostovtsev
Copy link
Member

feat: create impersonated service credentials
feat: add duplication mechanism to various credentials to support "re-scoping" them for IAM requests

@viacheslav-rostovtsev viacheslav-rostovtsev requested a review from a team as a code owner November 2, 2024 03:36
@viacheslav-rostovtsev viacheslav-rostovtsev force-pushed the dev/virost/impersonated_creds branch 2 times, most recently from 3a8238c to 68627a3 Compare November 5, 2024 01:41
Copy link
Member

@dazuma dazuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question: what kind(s) of credentials are acceptable base credentials for these impersonated credentials? Is it just service account creds, or does it include compute engine creds, or external creds?


describe "duplicates" do
before :example do
Google::Cloud.env.compute_smbios.override_product_name = "Google Compute Engine"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably undo this in an after clause, so it doesn't affect other tests.

# and then that claim is exchanged for a short-lived token at an IAMCredentials endpoint.
# The short-lived token and its expiration time are cached.
class ImpersonatedServiceAccountCredentials
ERROR_SUFFIX = <<~ERROR.freeze
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark this # @private so it's not part of the public interface

from IAM Credentials endpoint using the credentials provided.
ERROR

IAM_SCOPE = ["https://www.googleapis.com/auth/iam".freeze].freeze
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be # @private also?

include Google::Auth::BaseClient
include Helpers::Connection

attr_reader :base_credentials
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each of these should have YARD documentation.

new options
end

def initialize options = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either document this or mark it # @private.

# to fetch short-lived impersionation access token
# @param impersonation_url [String] the URL to use to impersonate the service account.
# This URL should be in the format:
# https://iamcredentials.{universe_domain}/v1/projects/-/serviceAccounts/{source_sa_email}:generateAccessToken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put backticks around the URL format string, otherwise YARD will try to linkify it.

# This URL should be in the format:
# https://iamcredentials.{universe_domain}/v1/projects/-/serviceAccounts/{source_sa_email}:generateAccessToken
# where:
# * {universe_domain} is the domain of the IAMCredentials API endpoint (e.g. 'googleapis.com')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put backticks around anything with literal curly braces, since it is a linkification syntax for YARD.

# and request short-lived credentials for a service account
# that has the authorization that your use case requires.
#
# @param base_credentials [Object] the authenticated principal that will be used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these parameters required? (Seems like they are.) If so, can you note that in the documentation, and also put some checks in the constructor to fail fast if they are not provided?

# See the License for the specific language governing permissions and
# limitations under the License.

spec_dir = File.expand_path File.join(File.dirname(__FILE__))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File.join() with only one argument is kind of a noop.

Also, I think this $LOAD_PATH hackery is unnecessary here. We're not requiring any files in the spec/googleauth directory like some of the other spec files are. (And even in those, this is an ugly way to require those files and should just be changed to require_relative.)


describe "#initialize" do
it "should call duplicate when available" do
allow(@base_creds).to receive(:duplicate).and_return(@base_creds)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe return something else so you can verify that source_credentials is that other thing rather than @base_creds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants