ASM
AppsScript Library to enable easy use of Google Secret Manager in AppsScript
Install / Use
/learn @graphicnapkin/ASMREADME
AppsScript Secrets Manager
Enabling you to easily fetch secrets from GCP Secrets Manager to use in your AppsScript projects. View the compiled output at https://script.google.com/home/projects/19bkwDLT1xtSGoXnHo_aoNft_A9h4h0IP5H0dwi2ScX45qxGk7uw3nPIZ/edit
Step 0: Create your Secrets (if you don't have any)
- Follow steps <a href="https://cloud.google.com/appengine/docs/standard/nodejs/building-app/creating-project">here</a> to create a GCP project.
- Follow steps <a href="https://cloud.google.com/secret-manager/docs/create-secret-quickstart">here</a> to create new secrets inside a GCP project.
- On the
Permissionstab clickGrant Accessand grant your users or groups access to this secret with theSecret Manager Secret Accessorrole. This role will enable them to only access this secret via API, not even through the GCP console. If you wish the to also have access via the console, add additional appropriate roles specific to your use case.
Step 1: Creating an Internal AppsScript Library
- Create an apps script project at script.google.com.
- Click on the gear for settings and check the
Show "appsscript.json" manifest file in the editorcheckbox. - Click on the
<>icon to bring up the code editor. - Click on the appscript.json file and add in the
oauthScopeskey with the list of strings from the example in this repository. - Click on
Code.gsand replace the contents of this file with the contents of theCode.jsfile in this repository. - Save the file and run the getSecret function by selecting it form the dropdown on the top of the toolbar and hitting the Run button. This should force an OAuth consent screen to appear, and you will want to authorize it with your account.
- Click on the
Deploybutton on the top right, thenNew Deployment - On the left click the gear to the right of
Select typeand chooseLibrary - Enter a description of your choice then click
Deploy - Click on the Share button on the top left (looks like a profile icon with a +)
- Add in the desired individual users, groups or change to anyone in your organization or public
Step 1: Alternative, use ASM library
- In your Apps Script file click the + next to libraries
- Paste in this scriptID: 19bkwDLT1xtSGoXnHo_aoNft_A9h4h0IP5H0dwi2ScX45qxGk7uw3nPIZ
- Import with whatever name you choose (ASM recommended)
Step 2: Using the Library
- Inside a script that you would like to access a secret, click on
<>to bring up the code editor. - Click on the
+to the right ofLibrariesunderneath the files in this project. - Search for your Library by the script ID which can be found between /projects/ and /edit when looking at the url of your library file. I recommend aliasing this as GASM
- Recommended: Utlize the
useSecretfunction which takes in as arguments:- proejctID: The numbericalID for your GCP project.
- secretName: The name you gave the secret in Secret Manager.
- secretVersion: Intiger representing the version of the secret, this will be 1 if you have not edited the value.
- A callback function that will utlize the secret: This function should take as it's first argument the fetched secrets value. It can have any number of additional arguments which will be passed to the callback function.
- Checkout the fetchWithBasicAuth and fetchWithBearerAuth if you are making a simple API call for ever better secrets management.
Motivation
There is no clear path for securley storing API secrets inside Google AppsScript. Most projects will use either ScriptProperties or UserProperties. Script Properties can be seen clearly in the UI since the updated IDE launched. UserProperties are more obscured but it still doesn't align well with most organizations security practices and feels more like security through obscurity than a real robust solution. GCP has a great solution for this (Secrets Manager) and in discussion with a friend it seemed like a simple integration would not be that hard to implement.
Other Thoughts
This project is likely only useful for Google Workspace / GCP Administrators. I chose not to make this a public Library and my reasoning for this was I feel most security organizations that would find this useful would likely also have a requirement to "self host" to ensure full control of the codebase. This may change in the future.
Related Skills
node-connect
349.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.7kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
