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

Discord slash command code to grant AWS access #276

Merged
merged 36 commits into from
Nov 16, 2024

Conversation

vikhyat187
Copy link
Contributor

@vikhyat187 vikhyat187 commented Oct 19, 2024

Date: 19th Oct

Developer Name: Vikhyat


Issue Ticket Number

Real-Dev-Squad/todo-action-items#253

Description

This change is for the discord command to grant AWS access to the developers, we can tag the developer and the group we wanted to add the user in.

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

image
Here I've ran the discord command and the user and the AWS group has been specified, it checks if the user is part of the AWS account if not, adds the user to the account and then to the AWS IAM group.
image
This is the screen which the user will see on trying to access the AWS link and they should reset their password by using the password sent to their email. (Emails are taken from our Firestore db)

Test Coverage

Screenshot 1 image
Writing the test cases will push the changes in the same PR
## Additional Notes
  1. We will have to create the groups in our AWS account and then store those values in our discord service before registering the command.
  2. We will have to create IAM access and secret keys and store them in the website backend PR - Added AWS config and identity store website-backend#2208

@vikhyat187 vikhyat187 self-assigned this Oct 19, 2024
package.json Outdated Show resolved Hide resolved
channelId: number
) {
const authToken = await jwt.sign(
{ name: "Cloudflare Worker", exp: Math.floor(Date.now() / 1000) + 2 },
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the name here?

Copy link
Contributor Author

@vikhyat187 vikhyat187 Oct 31, 2024

Choose a reason for hiding this comment

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

in the website backend, we check if the auth token has the name "cloudfare workers" to validate the token coming from right source.

Ref : https://github.com/Real-Dev-Squad/website-backend/blob/f8d76e1936647759ef7fdfd513f7ff03de226346/middlewares/authorizeBot.js#L18

Copy link
Contributor

Choose a reason for hiding this comment

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

how is a string helping in validating the right source?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we create a token in the discord slash commands with name present in payload, this is signed by using the private key and in website backend we validate if the same text is being received post validating the token.
@prakashchoudhary07

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to discuss on this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TraceId: string,
channelId: number
) {
const authToken = await jwt.sign(
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we already have this? why write it again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

didn't get this comment, we are using this in similar manner in one of the other API too.

Copy link
Contributor

Choose a reason for hiding this comment

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

So at every place we are manually signing, So don't already have a common thing to do this, if not then please create one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have created a common utility for this.

userId: discordUserId,
};

const url = `${base_url}/aws-access/`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you create the URL in constant it self?

Copy link
Contributor

Choose a reason for hiding this comment

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

And please share the doc for using it herE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we mean it like
const url = ${base_url}/aws-access this way we have it stored?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't get this which doc?

And please share the doc for using it herE?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please share the AWS API docs like, of what they are doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is our website backend API, will add the comments there.

samarpan1738
samarpan1738 previously approved these changes Nov 11, 2024
joyguptaa
joyguptaa previously approved these changes Nov 11, 2024
Copy link
Member

@vinit717 vinit717 left a comment

Choose a reason for hiding this comment

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

Why this command is not under feature flag?

@vikhyat187
Copy link
Contributor Author

When I discussed with Tejas about feature flag he suggested to have the backend route under ff and since this command can be only used by super user didn't add the ff @vinit717

@vikhyat187
Copy link
Contributor Author

vikhyat187 commented Nov 12, 2024

Hi @vinit717 facing difficulty in local in registering the commands, so not able to validate the feature flag changes, can we move without it?

Sent the response here https://discord.com/channels/673083527624916993/688816539775926272/1305931857631645787

Have added the feature flag, and also fixed the register command which was failing, the reason is mentioned here https://discord.com/channels/673083527624916993/688816539775926272/1306095480836591626
image

@vikhyat187 vikhyat187 dismissed stale reviews from samarpan1738 and joyguptaa via e04b977 November 13, 2024 02:28
@vinit717
Copy link
Member

Please update the description and screenshots first

@prakashchoudhary07 prakashchoudhary07 merged commit b3ad69d into develop Nov 16, 2024
2 checks passed
@prakashchoudhary07 prakashchoudhary07 deleted the grant-aws-access branch November 16, 2024 18:26
@vikhyat187 vikhyat187 mentioned this pull request Nov 16, 2024
10 tasks
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.

7 participants