Skip to main content
INS // Insights

Slack bot tokens out of Lambda env

Updated November 2026 · 7 min read

Rutagon removes standing Slack bot tokens from Lambda environment variables, for a team whose function config still holds an xoxb token that can post as the bot until someone remembers to rotate it. A slack bot token environment variable is deleted from the function, and the function calls Slack with token rotation.

Book a technical call

slack bot token environment variable

The environment variable is the wrong place for a bot token. Anyone who can read the function configuration can read it. A deployment package that baked the same value into a file is the same defect. The token is standing: it works until a human rotates it, and the rotation is usually late. Slack token rotation issues an access token that expires and a refresh token the app uses to obtain the next one. The function asks for a valid access token at invoke. It does not carry a permanent xoxb in its environment block.

Slack documents that rotation on the token rotation page. We enable it on the app you already own. We do not create a second Slack app with a copied standing token and call that rotation. The old token is revoked after a successful invoke with the rotated token. Revoke first is an outage. Leave the old token in the environment after the new path works, and the finding is still there.

Lambda environment variables are visible to principals who can read the function. That exposure is described in the Lambda environment variable documentation. Deleting the variable is the point. Moving the same xoxb into a different environment key is not. The refresh material lives in a secret the function's execution role can read, not in the environment block and not in the deployment zip.

Secrets Manager rotation is the neighboring pattern when the secret is an AWS secret you rotate on a schedule. Slack's own rotation is what expires the bot token. The secret store only holds the refresh material Slack gave the app. Task roles versus access keys is the same refusal of a standing cloud key, applied here to the function role that reads the secret. The function does not get an AWS access key either. Security automation is the lane.

Rutagon does the cutover from Alaska. Every function whose environment, layer, or repository contains an xoxb used for this bot is on the list. A token in a shared layer is one fix, not one fix per function that forgot to inline it.

What the function does at invoke

The execution role reads the refresh material and exchanges it for an access token when the one in memory has expired. The access token is used for the Slack call and dropped. It is not written to CloudWatch logs. A debug line that prints the Authorization header is removed. We read a sample invoke log after the change and show the token is absent.

The refresh material is updated when Slack rotates it. The function role can write the new refresh value back to the secret. It cannot read every secret in the account. The resource policy on that secret names the role. A wildcard secret read is the standing-key habit in a different costume, and we do not ship it.

function: the Lambda that calls Slack
env_removed: the xoxb variable
token_source: Slack token rotation
refresh_store: a secret the execution role can read
aws_auth: the execution role, no static access key
log_check: a sample invoke with the token absent
revoked: the previous standing bot token

Configuration tokens and app-level credentials that install the app are not the bot token. We do not paste an app configuration token into the function so it can mint its own installs. Installation stays an admin act. The function only refreshes the bot token for the workspace you already installed.

Multiple functions that post as the same bot share the same rotation client. Two functions refreshing without coordination can invalidate each other's refresh token. One writer updates the secret. The others read. We do not leave each function with a private copy of the refresh token in its own environment. That copy is the bug returning.

What we delete

The environment variable is removed in the function configuration and in the template that sets it. A template that still injects the xoxb will put the finding back on the next deploy. The template change is part of the engagement when you authorize the repository. A value in a plain-text example, a README, or a test fixture is removed in the same pass. Tests use a fake. They do not use a revoked production token, and they do not use a new standing token.

Local invoke configurations on laptops are on the list. A developer dotfile with the xoxb will be copied into the next function. We replace that invoke path with a role the developer can assume, or we document that local invoke does not call Slack for real. An undocumented laptop copy is not an exception we accept.

The old token is revoked in Slack after the production invoke succeeds. We confirm the revoke by showing the old token fails and the rotated path still posts or reads what the function must do. A revoke we cannot prove is not marked done. If the bot is mid-incident and you need the old path for a named window, the window is short, written down, and the variable is still removed at the end of it. The window is not "until someone remembers."

We will not store the standing xoxb in Secrets Manager and leave rotation off. That is a relocation. The user-visible environment variable would be gone and the standing token would remain. The delivery is rotation plus the environment variable gone plus the old token revoked.

What the bot is still allowed to do

Scopes on the Slack app stay as narrow as the calls require. Rotation does not grant new scopes. If the app is an admin of the workspace and the function only posts to one channel, we remove the extra scopes when you confirm the app is not used for those admin calls elsewhere. If it is used elsewhere, we say so and we do not break the other use to make this function look tight. A second, narrow app is the right split when one app has become a god bot. That split is included when both apps are yours to change. It is named, not sneaked.

The function's AWS role can invoke the Slack HTTPS endpoint and read the one secret. It cannot administer the account. No static AWS key is added to "make the secret easier." Easier is how the xoxb landed in the environment the first time.

Handover is the function configuration without the variable, the rotation enabled, the secret policy, the sample log, and the revoked token. Your next function that needs Slack uses the same client. It does not get a fresh xoxb pasted into an environment form. On a production SaaS platform a token in an environment variable was treated as a standing credential even when the rest of the deploy used roles. This function catches up to that rule.

Frequently Asked Questions

Do you put the same xoxb in Secrets Manager and stop?

No. A standing bot token in a secret store is still a standing bot token. Slack token rotation replaces it with an expiring access token and a refresh flow. The old token is revoked after a successful invoke, and the environment variable is removed.

Where does the refresh token live?

In a secret the function's execution role can read and update. It is not a Lambda environment variable and it is not in the deployment package. The role cannot list every secret in the account. The access token itself is not written to logs.

What if two functions refresh the same bot?

One writer updates the shared secret. The other functions read it. Separate copies of the refresh token in each environment will invalidate each other. We do not leave those copies.

Will a template put the variable back?

If it would, we change the template in the repository you authorize before we call the work done. A console delete that the next deploy reverses is not a removal. Example tokens in docs and tests are removed in the same pass.

Do you also remove AWS access keys from the function?

The function uses its execution role. We do not add a static AWS key for the secret read. Keys already on the function for this call are removed as part of the same cutover. Unrelated keys in other services are named, not silently expanded into a new program.

Book a technical call. 907-841-8407. contact@rutagon.com.