Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 37 ยท Operations and Alternatives

Security, Teams and Access

Secure a Heroku app: team roles and collaborators, two-factor authentication, handling secrets in config vars, token hygiene, Private Spaces and Shield, and a security audit stand-in.

Heroku secures the platform: the hosts, the network, the managed databases. You secure what you put on it: your code, your secrets and who can change things. This lesson covers the access controls Heroku gives you and the habits that prevent the usual incidents. The platform cannot run on this site; commands are read-only text, and the audits are runnable stand-ins.

Shared responsibility

Heroku is responsible for the infrastructure, patching the stack (the base OS image), isolating dynos and encrypting managed databases at rest. You are responsible for application vulnerabilities, dependency updates, account access, secrets and the data you store. Dependency updates matter a lot: a stack upgrade does not fix an old library in your requirements.txt or package.json.

Accounts, teams and roles

Personal accounts suit solo projects. For a company, create a Heroku Team (called an enterprise team on the largest plans). A team owns apps, so access does not vanish when a person leaves, and it gives roles:

Role Can
Admin Manage members, billing and all apps
Member Create apps and work on apps they have access to
Collaborator Access only the apps they are added to
Viewer Read-only access to the dashboard

Names and exact permissions vary by plan, so check the current docs. Practice least privilege: most developers need collaborator or member access to staging and fewer to production; the person who deploys to production is a short list.

Terminal
heroku access --app my-app
heroku access:add [email protected] --permissions deploy,operate --app my-app
heroku access:remove [email protected] --app my-app

Turn on two-factor authentication for every account, and require it team-wide in the team settings. Use hardware keys or an authenticator app, not SMS only. Remove people from the team the day they leave.

Secrets and config vars

Config vars are environment variables stored encrypted by Heroku and injected into dynos. They are the right place for passwords, API keys and signing secrets.

Terminal
heroku config --app my-app
heroku config:set STRIPE_KEY=... --app my-app
heroku config:unset OLD_KEY --app my-app

Rules:

  1. Never commit secrets to Git. If one slips in, rotate it (create a new key, update the config var, revoke the old one); deleting the commit is not enough because the history is copied everywhere.
  2. Different secrets per environment: staging must not hold production keys.
  3. Remember that anyone with operate access can read the config vars of an app, so production access means secret access.
  4. Do not echo variables into logs or error pages.
  5. Rotate regularly and on staff changes.

Some Heroku add-ons rotate their credentials themselves (Postgres, for example); apps that read DATABASE_URL at start-up keep working after the automatic restart.

Tokens and the CLI

heroku login stores a token on your computer. Treat it like a password. Use heroku authorizations:create to make scoped, expiring tokens for CI systems instead of a person's personal token, and revoke them when no longer needed (heroku authorizations:revoke). Never paste heroku auth:token output into chat tools or tickets.

Network and compliance options

  • All traffic to *.herokuapp.com is HTTPS-capable, and custom domains can use managed certificates.
  • Private Spaces give an app an isolated virtual network with its own private routing, private Postgres, IP-range controls and static outbound IPs for partners that allow-list addresses.
  • Shield adds controls for regulated data such as health information (extra logging and encryption features).
  • For compliance questions (SOC 2, ISO 27001, GDPR, HIPAA) read Heroku's current compliance pages and sign any needed agreements before you store regulated data.
flowchart TD
    A["Public internet"] --> R["Heroku router<br/>(HTTPS)"]
    R --> W["Common runtime dynos"]
    P["Private Space<br/>isolated network"] --> W2["Private dynos"]
    W2 --> DB[("Private Postgres")]

Common runtime apps share routing infrastructure; Private Spaces isolate a network for one customer.

Application-level security checklist

  • Keep dependencies up to date (automated alerts from your Git host or a scanner).
  • Force HTTPS in your app (redirect or HSTS header); the router terminates TLS but passes X-Forwarded-Proto.
  • Trust the proxy headers correctly (for client IPs and protocol) and nothing else.
  • Parameterize SQL, escape output, protect forms against CSRF, set secure cookie flags.
  • Add rate limiting for login and expensive endpoints.
  • Do not rely on obscurity of the *.herokuapp.com name: anyone can find it.
Python Stand-in: audit config variables for risky values

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both environments report the weak secret; staging also reports the live key, and production reports DEBUG. Real audits add more rules, but the idea of codifying checks in a script is the same.

Python Stand-in: who can touch production?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Keep this list short, review it every quarter, and remember that the right to deploy usually includes the right to read secrets.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What should you do after committing an API key to Git by mistake?

    The key may already be copied; only creating a new one and revoking the old one is safe.
  2. 2. Why use a Heroku Team rather than a personal account for a company app?

    Team ownership and roles give central control and easier offboarding.
  3. 3. What is a Private Space?

    Private Spaces give a dedicated, isolated network with private routing and controlled IP ranges.
  4. 4. Which token approach is best for CI?

    Scoped tokens can be revoked without affecting a person's account.

Summary

  • Heroku secures the platform; you secure code, secrets, dependencies and access.
  • Use teams, least-privilege roles and mandatory two-factor authentication.
  • Keep secrets in config vars, separate per environment, rotate after leaks and departures.
  • Use scoped tokens for CI; consider Private Spaces or Shield for isolation and regulated data.

Next: Custom Domains and TLS