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

chore: improve metrics/logs for checkUserAccess/checkAdminAccess #139

Merged
merged 4 commits into from
May 22, 2024

Conversation

enzomerca
Copy link
Contributor

What problem is this solving?

Improve logging and metrics on checkUserAccess and checkAdminAccess directives. This will help us understand how these APIs are used.

This change keeps previous authentication behavior, it just make sure to validate all provided tokens and emit metric before applying rules.

How should this be manually tested?
Tested calling APIs with each directive with multiple different authentication methods.

@enzomerca enzomerca requested a review from Rudge May 17, 2024 18:34
Copy link

vtex-io-ci-cd bot commented May 17, 2024

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖

Please select which version do you want to release:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 😞

Copy link

github-actions bot commented May 17, 2024

Warnings
⚠️

Looks like this PR is too large [:bulb: smaller PRs are easy to review and approve]

Messages
📖 ❤️ Thanks!
📖

🎉 PR additions = 259, PR deletions = 185

Generated by 🚫 dangerJS against bfa67a2

@@ -157,7 +16,155 @@ export class CheckUserAccess extends SchemaDirectiveVisitor {
context: Context,
info: any
) => {
await checkUserOrAdminTokenAccess(context, field.astNode?.name?.value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this extra function call as there was no real gain with it and to keep same style as checkAdminAccess directive

@@ -14,4 +14,14 @@ export default class IdentityClient extends JanusClient {
public async validateToken({ token }: { token: string }): Promise<any> {
return this.http.post('/api/vtexid/credential/validate', { token })
}

public async getToken({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The storefront-permissions app was not properly handling appkey/apptokens. Now we can get a token from identity for a given appkey/apptoken and allow/block requests properly.

node/directives/checkAdminAccess.ts Outdated Show resolved Hide resolved
if (!adminUserAuthToken) {
metric.error = 'No admin token provided'
sendAuthMetric(logger, metric)
sendAuthMetric(logger, auditMetric)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we validate all possible tokens above so we can emit a metric here with all the necessary data, and below we actually apply the validations and allow/block the request.

Copy link

@enzomerca enzomerca merged commit 482d1a8 into master May 22, 2024
13 checks passed
@enzomerca enzomerca deleted the chore/B2BTEAM-1640-improve-metrics branch May 22, 2024 11:40
Copy link

vtex-io-ci-cd bot commented May 22, 2024

Your PR has been merged! App is being published. 🚀
Version 1.40.4 → 1.40.5

After the publishing process has been completed (check #vtex-io-releases) and doing A/B tests with the new version, you can deploy your release by running:

vtex deploy [email protected]

After that your app will be updated on all accounts.

For more information on the deployment process check the docs. 📖

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.

2 participants