How to Share API Keys Securely with Contractors
A contractor needs access to your Stripe API, your AWS credentials, or your database connection string. The project starts Monday. What do you do? If the answer involves pasting the key into a Slack DM, emailing it in plaintext, or dropping it in a shared Google Doc, you are creating a security liability that will outlast the contractor's engagement by months or years. This guide covers five concrete methods for sharing API keys with contractors securely, along with access scoping strategies and a complete offboarding checklist.
Why Slack and Email Are Dangerous for API Keys
The instinct to share credentials through everyday communication tools is understandable. Slack and email are fast, familiar, and both parties already have accounts. The problem is that these platforms were designed for communication, not credential management. Their retention and access characteristics make them uniquely dangerous for sensitive data.
The Slack Problem
When you paste an API key into a Slack message, the following happens:
- The key is stored on Slack's servers indefinitely. Even in free workspaces (which only display 90 days of messages), the data is retained on Slack's backend. Enterprise Grid workspaces retain all messages and make them searchable by workspace owners and compliance admins.
- Slack messages are searchable. Anyone with access to the channel (or admin access to the workspace) can search for the key. A simple search for "sk_live" or "AKIA" will surface every Stripe or AWS key ever shared in your workspace.
- Slack data can be exported. Workspace owners can export all messages, including DMs on paid plans. A compromised owner account means every credential ever shared in Slack is compromised.
- Slack integrations can read messages. Third-party apps installed in your workspace may have access to message content. Each integration is a potential data exfiltration vector.
- The key persists after the contractor leaves. When you deactivate a contractor's Slack account, the messages containing API keys remain in the workspace. The key is still there, searchable, accessible to anyone with the right permissions.
The Email Problem
Email is even worse than Slack for credential sharing:
- Emails are stored in the sender's Sent folder, the recipient's inbox, and potentially in multiple email server backups
- Emails can be forwarded to anyone without your knowledge or consent
- Most email is transmitted without end-to-end encryption (TLS encrypts in transit but the email provider can read the content)
- Email accounts are the most commonly compromised accounts in business environments. A phished email account exposes every credential ever received via email
- Email subject lines and body content are indexed by email providers for search and, in some cases, advertising
The Real Cost of Leaked Credentials
API key leaks are not theoretical risks. They happen constantly and the costs are concrete:
- AWS key exposure: Attackers scan GitHub, Slack exports, and public paste sites for AWS access keys. Within minutes of a key appearing publicly, automated bots spin up cryptocurrency mining instances. Victims report bills of $10,000-50,000 within hours. AWS has a policy of reducing these charges in some cases, but the process takes weeks and is not guaranteed.
- Stripe key exposure: A leaked Stripe live key allows an attacker to issue refunds, create charges, access customer payment information, and modify your account configuration. The financial and reputational damage from unauthorized transactions can be devastating.
- Database credential exposure: Leaked database connection strings give attackers direct access to your data. Depending on the permissions, they can read, modify, or delete data, or use the database server as a pivot point for further network access.
- OAuth client secrets: Leaked client secrets allow attackers to impersonate your application, access user data through your OAuth grants, and potentially escalate to full account takeover of your users.
The average cost of a credential-related breach reached $4.6 million in 2025 according to IBM's Cost of a Data Breach Report. For API key leaks specifically, the median cost per incident is lower but the frequency is far higher, making aggregate costs substantial for organizations that routinely share credentials insecurely.
Share API Keys That Self-Destruct
Create an encrypted, view-once link for your API credentials. AES-256-GCM encryption, zero knowledge, automatic expiration. The key is never stored in message history.
Create Secure ShareMethod 1: Self-Destructing Encrypted Links
For ad-hoc credential sharing where you need to get an API key to a contractor quickly, encrypted self-destructing links are the most practical solution. The workflow takes under 30 seconds:
- Go to SecureBin and paste the API key (or multiple credentials)
- Set the link to expire after one view (view-once) or within a specific time window
- Optionally add a password and communicate it through a separate channel
- Send the generated link to the contractor
- The contractor opens the link, copies the credentials, and the link is permanently destroyed
Why this works: The credential is encrypted with AES-256-GCM in your browser before it reaches the server. The decryption key is in the URL fragment (after the #), which is never sent to the server. After the contractor views it, the encrypted data is deleted. There is no copy in Slack history, no email to forward, no document to share accidentally. The credential existed in a retrievable form for exactly the time the contractor needed to access it.
Best practice: Send the link through one channel (email or Slack) and the password through a different channel (phone call, SMS, or Signal). This way, compromising one channel does not expose the credential.
Method 2: Secrets Managers
For ongoing contractor engagements where multiple credentials need to be managed, a secrets manager provides centralized control. The major options are:
Cloud Provider Secrets Managers
- AWS Secrets Manager: Create a secret, grant the contractor's IAM user or role access via an IAM policy. Access is automatically revoked when you remove the policy. Integrates with AWS services natively. $0.40/secret/month + $0.05/10,000 API calls.
- GCP Secret Manager: Similar model using IAM bindings. Integrates with Cloud Functions, Cloud Run, and GKE. $0.06/10,000 access operations.
- Azure Key Vault: RBAC-based access control for secrets, keys, and certificates. Integrates with Azure services and supports hardware security modules (HSMs). $0.03/10,000 operations.
Third-Party Secrets Managers
- HashiCorp Vault: Open-source with an enterprise edition. Dynamic secrets (generates temporary credentials on demand), leasing (credentials auto-expire), and comprehensive audit logging. The most powerful option but requires operational investment to run. Good choice if you already run Vault for other purposes.
- 1Password for Teams/Business: Shared vaults with role-based access. Less technical overhead than Vault. Good for teams that already use 1Password. $7.99/user/month for Business.
- Doppler: Purpose-built for application secrets. Syncs secrets to environments, CI/CD pipelines, and cloud providers. $4/user/month for Team plan.
When to use a secrets manager vs. encrypted links: Use a secrets manager when the contractor needs ongoing access to credentials that may change (e.g., credentials that rotate regularly), when multiple credentials need to be managed, or when you need detailed audit logging of credential access. Use encrypted links for one-time shares, quick onboarding, or when the contractor does not need to be provisioned in your infrastructure.
Method 3: Environment Variable Injection
The most secure method for providing API keys to a contractor's application code is to inject them as environment variables, so the contractor never sees the actual key value at all. This is the gold standard for production systems.
CI/CD Pipeline Injection
If the contractor works through your CI/CD pipeline, store secrets in your pipeline's secret storage:
# GitHub Actions - secrets are injected as env vars
env:
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
# GitLab CI - CI/CD variables
variables:
STRIPE_API_KEY: $STRIPE_API_KEY # Set in Settings > CI/CD > Variables
The contractor writes code that reads from environment variables. They push code to the repository. The CI/CD pipeline injects the actual credentials at build or deploy time. The contractor never has direct access to the credential values.
Container-Based Injection
For containerized applications, inject secrets at runtime:
# Docker - inject at runtime, never bake into images
docker run -e STRIPE_API_KEY="sk_live_..." myapp
# Kubernetes - use Secrets objects
apiVersion: v1
kind: Secret
metadata:
name: api-credentials
type: Opaque
stringData:
STRIPE_API_KEY: sk_live_...
The contractor's Dockerfile references the environment variable. The actual value is injected by the orchestration platform, not stored in the container image or repository.
Development Environment Injection
For local development, use .env files (never committed to version control) or a tool like direnv that loads environment variables when entering a project directory:
# .env file (MUST be in .gitignore)
STRIPE_API_KEY=sk_test_...
DATABASE_URL=postgres://user:pass@host/db
# .gitignore
.env
.env.local
.env.*.local
Share the .env file contents through an encrypted self-destructing link rather than committing it to the repository or sending it via Slack. For more on keeping keys out of code, see our guide on securing API keys in code.
Access Scoping and Key Rotation
The principle of least privilege is critical when sharing API keys with contractors. Never give a contractor your master API key when a scoped key with limited permissions will work.
Creating Scoped API Keys
Most API providers support creating keys with restricted permissions:
- Stripe: Restricted keys can be limited to specific resources (charges, customers, subscriptions) and specific operations (read, write). Create a restricted key that only has the permissions the contractor needs.
- AWS: Create an IAM user or role with a policy that grants only the specific API actions and resources the contractor needs. Never share root account credentials or admin keys.
- GitHub: Fine-grained personal access tokens can be scoped to specific repositories and specific permissions (read-only, issues only, etc.).
- Google Cloud: Service accounts with custom IAM roles scoped to the minimum required permissions.
- Twilio: API keys can be created per project and revoked independently of your main account credentials.
If the API provider does not support scoped keys, consider using an API gateway or proxy that limits which endpoints the contractor's key can access.
Key Rotation Strategy
API keys shared with contractors should be rotated on a defined schedule and always rotated when the engagement ends:
- During engagement: Rotate keys every 90 days for long-term contractor engagements. This limits the window of exposure if a key is compromised without the contractor's knowledge.
- At offboarding: Rotate every key the contractor had access to within 24 hours of the engagement ending. Do not wait. Do not assume the contractor deleted the key.
- After incidents: If you suspect a key may have been compromised (contractor's laptop stolen, contractor's email hacked, suspicious API activity), rotate immediately. Investigate after the rotation, not before.
Automate rotation where possible. AWS Secrets Manager supports automatic rotation with Lambda functions. HashiCorp Vault can generate dynamic credentials that auto-expire. For keys that must be rotated manually, set calendar reminders and treat missed rotations as security incidents. For a comprehensive approach, see our guide on API key rotation best practices.
Need to Share Credentials Right Now?
Create an encrypted link in 10 seconds. View-once, password-protected, auto-expiring. No account required for you or the recipient.
Share Credentials SecurelyContractor Offboarding Security Checklist
When a contractor engagement ends, follow this checklist to ensure no credential exposure persists:
- Inventory all credentials shared. Review your records (encrypted sharing links, secrets manager access logs, CI/CD variable assignments) to compile a complete list of every credential the contractor had access to.
- Rotate all shared credentials. Every API key, database password, SSH key, and OAuth token the contractor accessed must be rotated. Generate new credentials and update all services that use them. This is non-negotiable regardless of how much you trust the contractor.
- Revoke secrets manager access. Remove the contractor's IAM policies, vault tokens, 1Password group membership, or whatever mechanism granted them access to your secrets manager. Verify the revocation by attempting to authenticate with the contractor's credentials.
- Revoke repository access. Remove the contractor from GitHub, GitLab, or Bitbucket. Check for deploy keys or personal access tokens that may still be active. Remove any SSH keys the contractor added to CI/CD systems.
- Revoke cloud console access. Delete the contractor's IAM user, service account, or SSO assignment. Check for federated access or assumed roles that may persist after the user is removed.
- Review API logs. Check API access logs for the 48 hours before offboarding. Look for unusual patterns: bulk data downloads, access to resources outside the contractor's scope, or API calls at unusual times. This is not about suspicion; it is about establishing a clean baseline.
- Revoke VPN and network access. Disable the contractor's VPN credentials, remove their IP from any allowlists, and revoke any network access tokens.
- Check for hardcoded credentials. Review any code the contractor committed for hardcoded credentials, connection strings, or embedded API keys. Use tools like
trufflehog,gitleaks, ordetect-secretsto scan the repository history. - Delete Slack messages containing credentials. If credentials were shared via Slack (they should not have been, but check), delete those messages. Note that message deletion may be restricted by workspace settings and that Slack retains data even after deletion for a period.
- Document the offboarding. Record the date, which credentials were rotated, which access was revoked, and who performed the offboarding. This documentation is required for SOC 2, ISO 27001, and other compliance frameworks.
Automate this checklist. If you regularly engage contractors, build a runbook or script that handles credential rotation, access revocation, and log review. Manual offboarding processes have a failure rate of 20-30% (at least one step gets missed).
Frequently Asked Questions
Is it safe to share API keys over Slack?
No. Slack messages are stored indefinitely on Slack's servers, searchable by workspace admins, and persisted in message history. If your Slack workspace is compromised, every API key ever shared in a message is exposed. Slack data exports (available to workspace owners) include all messages, including DMs on paid plans. A single compromised admin account exposes every credential ever shared in Slack. Use encrypted self-destructing links or a secrets manager instead.
How do I revoke a contractor's API access?
Immediately rotate or delete the API keys the contractor had access to. If you used a secrets manager, revoke their access policy. If you used scoped keys, delete the contractor-specific key. Check API logs for the contractor's key usage in the 24-48 hours before offboarding to ensure no unusual activity. Update any services that used the old keys with the new rotated keys. Document the revocation date for compliance records.
What happens if an API key is leaked?
A leaked API key gives the attacker the same access as the legitimate key holder. Depending on the key's permissions, this could mean reading customer data, making purchases, modifying infrastructure, or deleting resources. The financial impact ranges from unexpected API charges (cryptocurrency mining via cloud keys has generated bills exceeding $50,000 in hours) to full data breaches costing millions. Immediately rotate the compromised key, review API logs for unauthorized usage, assess what data or systems were accessed, and notify affected parties if customer data was exposed.
Related Articles
Continue reading: API Key Rotation Best Practices, How to Secure API Keys in Code, Enterprise Password Sharing Solutions, SOC 2 Secret Management Requirements.
Usman has 10+ years of experience securing enterprise infrastructure, managing high-traffic servers, and building zero-knowledge security tools. Read more about the author.