-
Notifications
You must be signed in to change notification settings - Fork 254
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
base: main
Are you sure you want to change the base?
feat: create impersonated service credentials #499
Conversation
3a8238c
to
68627a3
Compare
743091e
to
2ed3089
Compare
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.
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" |
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.
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 |
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.
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 |
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.
Should this be # @private
also?
include Google::Auth::BaseClient | ||
include Helpers::Connection | ||
|
||
attr_reader :base_credentials |
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.
Each of these should have YARD documentation.
new options | ||
end | ||
|
||
def initialize options = {} |
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.
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 |
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.
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') |
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.
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 |
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.
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__)) |
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.
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) |
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.
maybe return something else so you can verify that source_credentials
is that other thing rather than @base_creds
.
feat: create impersonated service credentials
feat: add duplication mechanism to various credentials to support "re-scoping" them for IAM requests