-
Notifications
You must be signed in to change notification settings - Fork 376
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: Fix impersonated service account parsing exception #1862
Conversation
Can I get any feedback on this? Or discussion on #1861 ? |
@blue-hope thanks for the PR! @lahirumaramba I notice you self-assigned the related issue #1703 - would you be able provide any input on how to move this forward? Thanks very much! |
@lahirumaramba |
Thank you everyone for your patience! Hey @blue-hope Thank you so much for the contribution! Just adding this note to let you know that I have started the review process. We also plan to migrate the credentials implementation to |
Thank you so much for reviewing. |
@lahirumaramba just a side-note on the migration to Run:
However, trying to authenticate with Identity Toolkit / Firebase Auth would fail:
Would the migration to |
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.
Hi @blue-hope, Thank you again for your contributions. It looks pretty good overall... I think we can improve the test coverage. Added a few comments and one question. Please take a look. Thanks!
function credentialFromFile(filePath: string, httpAgent?: Agent): Credential { | ||
const credentialsFile = readCredentialFile(filePath); | ||
function credentialFromFile(filePath: string, httpAgent?: Agent, ignoreMissing?: boolean): Credential | null { | ||
const credentialsFile = readCredentialFile(filePath, ignoreMissing); |
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.
Correct me if I am wrong here, but it looks like by setting ignoreMissing
we turn off the Failed to read credentials from file
error. I think if GOOGLE_APPLICATION_CREDENTIALS
is set and getApplicationDefault()
is called we should still throw if it is an incorrect file path, right?
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.
Sure, so I passed ignoreMissing
as false when check GOOGLE_APPLICATION_CREDENTIALS
on line 486. So we still can encounter FirebaseAppError
when an incorrect file path is passed.
const c = getApplicationDefault(); | ||
expect(c).to.be.an.instanceof(ImpersonatedServiceAccountCredential); | ||
}); | ||
|
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.
Let's add another test to httpAgent
:
it('ImpersonatedServiceAccountCredential should use the provided HTTP Agent', () => {
const agent = new Agent();
const c = new ImpersonatedServiceAccountCredential(MOCK_IMPERSONATED_TOKEN_CONFIG, agent);
return c.getAccessToken().then((token) => {
expect(token.access_token).to.equal(expectedToken);
expect(stub).to.have.been.calledOnce;
expect(stub.args[0][0].httpAgent).to.equal(agent);
});
});
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.
Actually, I think we can improve the test coverage for ImpersonatedServiceAccountCredential
. Please see describe('RefreshTokenCredential', () => {
for an example.
Let's also add another test in describe('isApplicationDefault()', () => {
it('should return true for ImpersonatedServiceAccountCredential loaded from GOOGLE_APPLICATION_CREDENTIALS', () => {
process.env.GOOGLE_APPLICATION_CREDENTIALS = path.resolve(__dirname, '../../resources/mock.impersonated_key.json');
const c = getApplicationDefault();
expect(c).is.instanceOf(ImpersonatedServiceAccountCredential);
expect(isApplicationDefault(c)).to.be.true;
});
it('should return false for explicitly loaded ImpersonatedServiceAccountCredential', () => {
const c = new ImpersonatedServiceAccountCredential(mockImpersonatedAccount);
expect(isApplicationDefault(c)).to.be.false;
});
I can't promise a timeline for this, but we are starting the initial work this year. It will be a bit complex migration so we plan to perform it in multiple stages. We will use #1377 to track any progress. |
Hi @IchordeDionysos, This looks a bit strange. |
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.
Thanks for addressing the review feedback! LGTM!
Let me know if you can add the missing unit tests. As an alternative, we can merge this as it is and I am happy to add the missing tests in a follow-up PR.
@lahirumaramba I'll add missing tests and notice to you before merge, thanks! |
@lahirumaramba New test added. I missed checking implicit discovered credential, thanks a lot. |
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.
Thank you @blue-hope! LGTM!
@lahirumaramba When this will be released? 😄 |
Definitively need this |
Thank you @blue-hope for your contribution. This feature is now included in the v11.5.0 release. Thanks folks for your patience on this! Try out the new feature if you get a chance and let us know what you think. |
Discussion
Testing
API Changes
RELEASE NOTE: Added support for initializing the SDK with service account impersonation in Application Default Credentials.