Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Rotate npm, GitHub & Cloud Credentials After a Supply Chain Attack

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

If you suspect a supply chain attack has compromised your development environment, the most urgent action is to rotate every credential that could have been exposed. This guide walks through rotating npm tokens, GitHub personal access tokens and SSH keys, and cloud provider credentials (AWS, Azure, GCP) in a careful order that limits further damage. You'll need admin access to your npm account, GitHub organization or account, and your cloud provider console, plus a clean machine to generate new keys.

What You'll Need

  • Admin access to the npm account(s) that publish or consume packages
  • Admin access to the GitHub organization or user account
  • Access to your cloud provider console (AWS, Azure, or GCP) with permission to rotate IAM credentials
  • A clean, trusted machine (not the one you suspect was compromised)
  • A password manager or secure vault to store new secrets

Step-by-Step

  1. Isolate the compromised environment. Immediately revoke the suspected machine's access to your network, disable its SSH keys, and disconnect it from any build pipelines. Do not delete anything yet—you'll need logs later.
  2. Rotate npm credentials.
    1. Log in to npmjs.com and go to Access Tokens. Delete all existing tokens, especially any with publish or read/write scope.
    2. Create a new token with the minimal scope needed (e.g., read for CI, or publish only for release jobs).
    3. If you use npm Enterprise or a private registry, rotate those credentials as well.
    4. Update your CI/CD pipeline secrets with the new token. Do not commit it to source control.
  3. Rotate GitHub credentials.
    1. Go to GitHub Settings → Developer settings → Personal access tokens. Revoke all fine-grained and classic tokens that were present on the compromised machine or in its environment variables.
    2. Generate new tokens with the least privilege required (e.g., repo scope for CI, or a fine-grained token limited to specific repos).
    3. If you use SSH keys, go to Settings → SSH and GPG keys and delete the compromised public key. Generate a new key pair on your clean machine with ssh-keygen -t ed25519 and add the public key to your GitHub account.
    4. For GitHub Apps or OAuth apps, revoke and re-authorize them, then update any stored client secrets.
  4. Rotate cloud provider credentials.
    1. AWS: In IAM, identify any access keys that were used on the compromised machine. Deactivate them first, then delete after confirming no active services depend on them. Create new access keys and attach them to the appropriate IAM user. Also rotate any temporary credentials (STS) and consider rotating your root account password if it was stored locally.
    2. Azure: In Microsoft Entra ID, revoke any service principal secrets and client secrets. For user accounts, force a password reset. Rotate storage account keys and any connection strings that were in environment variables.
    3. GCP: In IAM & Admin, delete service account keys that were exposed. Create new keys and download them securely. Also revoke OAuth tokens and rotate API keys for any Google Cloud services.
  5. Update all secrets in your CI/CD and local environments. Go through every pipeline (GitHub Actions, GitLab CI, Jenkins, etc.) and replace the old tokens and keys with the new ones. Also check .env files, Docker secrets, and your local shell profile.
  6. Audit access logs. After rotating, review logs from npm, GitHub, and your cloud provider for any unauthorized activity after the suspected compromise time. Look for unusual IPs, new repos, or API calls you didn't make.
  7. Monitor for further anomalies. Set up alerts for new access tokens, new SSH keys, or IAM changes. Many providers offer built-in anomaly detection—enable it if you haven't.

Common Mistakes

  • Rotating credentials on the same compromised machine—keyloggers or malware can capture the new ones.
  • Only rotating npm tokens but forgetting GitHub PATs that are stored in the same .npmrc or environment file.
  • Deleting cloud access keys without first updating services that use them, causing outages.
  • Reusing the same password or token pattern across accounts.
  • Not checking for other secrets like database passwords or third-party API keys that were in the same environment.

Tips

  • Use short-lived tokens where possible—GitHub fine-grained tokens and AWS STS tokens can expire automatically.
  • Store all new credentials in a password manager that supports TOTP for extra security.
  • Enable two-factor authentication (2FA) on npm, GitHub, and your cloud provider if you haven't already.
  • Consider using a dedicated deployment user with minimal permissions instead of your personal account.
  • Document the rotation process so you can repeat it quickly if needed.

Troubleshooting

CI builds fail after rotation. This usually means a pipeline still references an old secret. Check the pipeline configuration and the secret store (e.g., GitHub Actions secrets, GitLab CI variables) to ensure the new token is correctly set.

You can't log into npm or GitHub. If your 2FA is tied to an authenticator app that was on the compromised device, you may need to use recovery codes or contact support to regain access.

Cloud provider shows 'access denied' for a service. You may have deleted a key that an application still uses. Recreate the key, update the application, then delete the old one after confirming the new one works.

You suspect the attacker still has access. If you see new credentials being created after rotation, you may have a persistent backdoor (e.g., a malicious GitHub Actions workflow). Review all workflows and remove any that are not yours.

Frequently Asked Questions

How quickly should I rotate credentials after a suspected attack?

Immediately. The longer you wait, the more time the attacker has to use the stolen credentials. Rotate the most critical ones first—cloud provider and GitHub—since they give broad access.

Do I need to rotate my npm password too?

Yes, if you suspect your machine was compromised, change your npm account password as well. Also revoke any active sessions from the npm website.

What if I can't access my cloud console because the attacker changed my password?

Use your provider's account recovery process, which typically involves email verification or contacting support. Once in, immediately enable 2FA and rotate all credentials.

Should I rotate credentials for third-party services like Slack or Datadog?

Yes, if those tokens were stored in the same environment or CI system, treat them as compromised and rotate them too.

How do I know if my credentials were actually stolen?

You may not know for sure, but if you suspect a supply chain attack, it's safer to rotate proactively. Look for unusual activity in logs, but don't wait for proof.

Can I reuse an old token if it was only exposed in a test environment?

No. Once a token is exposed anywhere, treat it as compromised and revoke it. Test environments are often less protected and can be a gateway to production.