|
| 1 | +--- |
| 2 | +meta: |
| 3 | + title: How to reference secrets in Serverless Jobs |
| 4 | + description: Steps to reference secrets from Secret Manager in your Serverless Jobs. |
| 5 | +content: |
| 6 | + h1: How to reference secrets in Serverless Jobs |
| 7 | + paragraph: Steps to reference secrets from Secret Manager in your Serverless Jobs. |
| 8 | +tags: serverless jobs secrets secret-manager reference environment variable |
| 9 | +dates: |
| 10 | + validation: 2024-10-27 |
| 11 | + posted: 2024-10-27 |
| 12 | +categories: |
| 13 | + - serverless |
| 14 | + - jobs |
| 15 | +--- |
| 16 | + |
| 17 | +Serverless Jobs seamlessly integrates with [Secret Manager](/identity-and-access-management/secret-manager/), which allows you to store, manage, and access sensitive information, such as credentials, SSH keys, SSL/TLS certificates, or any key/value pairs you need to secure. |
| 18 | + |
| 19 | +You can reference any secret stored in Secret Manager in a job, without having to hardcode any sensible data. |
| 20 | + |
| 21 | +<Macro id="requirements" /> |
| 22 | + |
| 23 | +- A Scaleway account logged into the [console](https://console.scaleway.com) |
| 24 | +- [Owner](/identity-and-access-management/iam/concepts/#owner) status or [IAM permissions](/identity-and-access-management/iam/concepts/#permission) allowing you to perform actions in the intended Organization |
| 25 | +- [Created a Serverless Job](/serverless/jobs/how-to/create-job-from-scaleway-registry/) |
| 26 | +- [Created a secret](/identity-and-access-management/secret-manager/how-to/create-secret/) |
| 27 | + |
| 28 | +## Add a secret to a job |
| 29 | + |
| 30 | +1. Click **Jobs** in the **Serverless** section of the side menu. The jobs page displays. |
| 31 | + |
| 32 | +2. Click the name of the job to which you want to add a secret, then open the **Settings** tab. |
| 33 | + |
| 34 | +3. In the **Secrets references** section, click **+ Add secret reference**. A pop-up displays. |
| 35 | + |
| 36 | +4. Select the secret you want to reference, and the desired version, then click **Select reference method**. |
| 37 | + |
| 38 | +5. Select the desired reference method: |
| 39 | + |
| 40 | + - **File**: copies the encrypted value of your secret to a file stored at the indicated location within your container. This method is recommended for large or complex data. For example, if your secret is a certificate, you can store it as a file in the `/my-certificates` folder in your container. |
| 41 | + |
| 42 | + - **Environment variable**: passes the encrypted value of your secret to your job as a variable. This method is recommended for small information, such as passwords, or API secret keys. For example, if you name this variable `MY_SECRET`, calling `$MY_SECRET` in your container will return the value of the selected secret in a secure way. |
| 43 | + |
| 44 | +6. Click **Add reference** to add the secret to your Serverless Job. Optionally, tick the **Add another reference** to add a new secret right away, then repeat steps 4 to 6. |
| 45 | + |
| 46 | +The secret is now referenced in your Serverless Job, and can be used within the container. |
| 47 | + |
| 48 | +## Update a secret in a job |
| 49 | + |
| 50 | +1. Click **Jobs** in the **Serverless** section of the side menu. The jobs page displays. |
| 51 | + |
| 52 | +2. Click the name of the job for which you want to update a secret, then open the **Settings** tab. |
| 53 | + |
| 54 | +3. In the **Secret references** section, click the <Icon name="edit" /> icon next to the secret reference you want to update. A pop-up displays. |
| 55 | + |
| 56 | +4. Update the secret version if needed, then click **Update** to save your changes, or click **Select reference method** to continue. |
| 57 | + |
| 58 | +5. Either update the location of the file, or the name of the environment, variable then click **Update reference** to confirm your changes. |
| 59 | + |
| 60 | +<Message type="note"> |
| 61 | +You cannot change the reference method of an existing secret. To do so, delete the secret reference within the job, then create it again with the desired reference method. |
| 62 | +</Message> |
| 63 | + |
| 64 | +## Delete a secret reference from a job |
| 65 | + |
| 66 | +1. Click **Jobs** in the **Serverless** section of the side menu. The jobs page displays. |
| 67 | + |
| 68 | +2. Click the name of the job for which you want to delete a secret, then open the **Settings** tab. |
| 69 | + |
| 70 | +3. In the **Secret references** section, click the <Icon name="delete" /> icon next to the secret reference you want to delete. A confirmation pop-up displays. |
| 71 | + |
| 72 | +4. Click **Delete reference** to confirm. |
| 73 | + |
| 74 | +The secret is no longer referenced in your Serverless Job. |
| 75 | + |
| 76 | +<Message type="note"> |
| 77 | +Deleting a secret from the **Settings** tab of a job only deletes the secret reference, not the secret itself. To permanently delete a secret, follow [this procedure](/identity-and-access-management/secret-manager/how-to/delete-secret/). |
| 78 | +</Message> |
0 commit comments