This repository contains a Node.js application designed to interact with Google Cloud services using the Google Cloud APIs. The application demonstrates retrieving IAM policies, roles, service accounts, and groups by leveraging the Google Cloud Identity and Access Management (IAM) API and Cloud Identity API.
I’ve also added queue functionality to different endpoints. However, a Redis server is required for it to work. The server can run either locally or remotely; simply update the .env file to configure the connection.
Note: This is a demo account, so I have synced the .env
file to GitHub. This is NOT a recommended practice for production environments. After the demo, I will make the repository private.
$ git clone [email protected]:andyyudev/OpsBerry-Engineering-Challenge.git
$ npm install
# Start the application in production mode
$ npm run start
# Start the application in development mode (watch mode)
$ npm run dev
GOOGLE_API_CREDENTIALS=/secrets/YOUR_GOOGLE_SERVICE_ACCOUNT_CREDENTIAL_JSON
GOOGLE_CUSTOMER_ID=YOUR_GOOGLE_CUSTOMER_ID
GOOGLE_PROJECT_ID=YOUR_GOOGLE_PROJECT_ID
** Add the credential json file in "/secrets/" directory.
- Go to the Google Cloud Console.
- Navigate to IAM & Admin > Service Accounts.
- Click on the service account you want to use or create a new one if necessary.
- To create a new service account, click Create Service Account, provide a name, description, and click Create.
- Click on Keys and then select Add Key > Create New Key.
- Choose the JSON key type and click Create. This will download your credentials file in JSON format.
- Save this file in "/secrets/" and set the GOOGLE_API_CREDENTIALS variable in your .env file to the path of this file.
- Go to the Google Admin Console.
- Click on Account > Account Settings > Profile.
- Your Customer ID is listed in the Customer Info section.
- Alternatively, you can use the Directory API to programmatically fetch the customer ID by making a request as an administrator of your domain.
- Go to the Google Cloud Console.
- Select IAM & Admin > Settings.
- The Project ID will be displayed at the top of the Settings page.
- You can also find the Project ID in the Dashboard or by navigating to any resource in the project.
- If you have multiple projects, you can use the project selector dropdown at the top of the page to select and view the Project ID of your desired project.
-
Get Identities
- Endpoint: GET /identities
- URL: http://localhost:3000/api/identities
- SOURCE: Uses the Google IAM API to retrieve a list of service accounts associated with a specified Google Cloud project.
-
Get Roles
- Endpoint: GET /roles
- URL: http://localhost:3000/api/roles
- SOURCE: Uses the Google IAM API to retrieve all predefined roles offered by Google Cloud and any custom roles defined within a specified Google Cloud project.
-
Get Groups
- Endpoint: GET /groups
- URL: http://localhost:3000/api/groups
- SOURCE: Uses the Google Cloud Identity API to retrieve groups associated with a specified Google Workspace or Cloud Identity customer.
-
Get Policies
- Endpoint: GET /policies
- URL: http://localhost:3000/api/policies
- SOURCE: Retrieves allow policies using the Google Cloud Resource Manager API and deny policies using the Google IAM API v2 for a specified Google Cloud project.
This is a simple example demonstrating the use of message queues between requests and services. A Redis server is required for this functionality to work; you can either run it locally or use a remote Redis server. Update the configuration in the .env file accordingly.
After making a request in the browser, you will see a status 202 response indicating that the job is currently queued for processing. The results will appear in the server’s console because I have not implemented a front-end UI to update the screen when the job is completed.
-
Get Identities
- Endpoint: GET /identities
- URL: http://localhost:3000/queues/identities
-
Get Roles
- Endpoint: GET /roles
- URL: http://localhost:3000/queues/roles
-
Get Groups
- Endpoint: GET /groups
- URL: http://localhost:3000/queues/groups
-
Get Policies
- Endpoint: GET /policies
- URL: http://localhost:3000/queues/policies
Since this is a simple demo, several key features were not implemented:
- Enable inputting custom credentials without relying on the .env file.
- Utilize secret management systems to securely store custom credentials.
- An API gateway for enhanced security measures, such as rate limiting, throttling, authentication, authorization, and handling CORS.
- Persistent data storage, which typically involves using a database, was not included.
- Mechanisms for API retries and handling failures have not been considered.
- Google API request pagination was not implemented; in a real-world application, each page token would be sent to message queues for further processing.
- Observability tools, such as Sentry, Winston, or other logging and monitoring solutions, were not included.
- And more...