1Password CLI: How NOT to Store Plaintext AWS Credentials on Localhost

1Password CLI: How NOT to Store Plaintext AWS Credentials on Localhost

No More ~/.aws/credetials

According to AWS security best practices, human users should access AWS services using short-term credentials provided by IAM Identity Center. Long-term credentials ("Access Key ID" and "Secret Access Key") created by IAM users should be avoided, especially since they are often stored in plaintext on disk: ~/.aws/credetials.

However, if you somehow have to use AWS access keys but want an extra layer of protection, 1Password CLI can help.

ref:
https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html
https://developer.1password.com/docs/cli/get-started

First, delete your local plaintext AWS credentials. Don't worry, you could generate new one any time on AWS Management Console.

rm -rf ~/.aws/credetials

Re-create aws-cli configuration file, but DO NOT provide any credentials.

aws configure

AWS Access Key ID [None]: JUST PRESS ENTER, DO NOT TYPE ANYTHING
AWS Secret Access Key [None]: JUST PRESS ENTER, DO NOT TYPE ANYTHING
Default region name [None]: ap-northeast-1
Default output format [None]: json

Edit ~/.aws/credentials:

[your-profile-name]
credential_process = sh -c "op item get \"AWS Access Key\" --account=my.1password.com --vault=Private --format=json --fields label=AccessKeyId,label=SecretAccessKey | jq 'map({key: .label, value: .value}) | from_entries + {Version: 1}'"

The magic is credential_process which sourcing AWS credentials from an external process: 1Password CLI's op item get command.

The one-liner script assumes you have an item named AWS Access Key in a vault named Private in 1Password, and the item has following fields:

  • AccessKeyId
  • SecretAccessKey

ref:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sourcing-external.html
https://developer.1password.com/docs/cli/reference/management-commands/item#item-get

That's it.

When you run aws-cli commands or access AWS services from your code via aws-sdk, your terminal will prompt you to unlock 1Password with biometrics to source AWS credentials (once per terminal session). No more plaintext AWS access keys on localhost!

# aws-cli
aws s3 ls --profile=perp
aws logs tail --profile=perp --region=ap-northeast-1 /aws/containerinsights/perp-staging/application --follow

# aws-sdk
AWS_PROFILE=perp OTHER_ENV=123 ts-node src/index.ts

# serverless v4 supports credential_process by default
# serverless v3 requires installing a plugin: serverless-better-credentials
# https://github.com/thomasmichaelwallace/serverless-better-credentials
sls deploy --stage=staging --aws-profile=perp

# if you're using serverless-offline, you might need to add the following configs to serverless.yml
custom:
  serverless-offline:
    useInProcess: true

It's worth noting that if you prefer not to use 1Password, there is also a tool called aws-vault which can achieve a similar goal.

ref:
https://github.com/99designs/aws-vault

No More .env

If you would like to store .env file entirely in 1Password, try 1Password Environments.

ref:
https://developer.1password.com/docs/environments
https://developer.1password.com/docs/environments/local-env-file

Surviving the Digital Dark Forest: Tips for Staying Safe Online

Surviving the Digital Dark Forest: Tips for Staying Safe Online

How I learned to "start worrying" and to embrace the illusion of safety.

Digital security and privacy have become more important than ever. With cyber threats constantly evolving, it is crucial to stay up-to-date with best practices and take proactive measures to protect your online presence. This comprehensive guide covers a wide range of security and privacy recommendations for various platforms and scenarios, aiming to help you fortify your digital life and assets.

General

  • Use a password manager: 1Password or Bitwarden.
    • Never reuse passwords.
    • Use strong passwords.
  • Always enable TOTP-based 2FA (Time-based One-Time Password).
    • Avoid SMS-based 2FA which is vulnerable to SIM swap attack.
    • Even you don't use SMS-based 2FA, your phone number might be used as a "Recovery Method".
  • Avoid using your password manager to generate one-time passwords for critical accounts.
  • Use Passkey.
  • Use security keys: YubiKey.
  • Use different email addresses when registering services if possible.
  • Always use HTTPS.
  • Don't blindly click links you see in your emails or search results; they could be scams!
    • Instead, add your frequently visited websites to your browser bookmarks.
  • Carefully review requested permissions when you connect third-party apps to your critical accounts.
  • Regularly review authenticated devices or sessions for your critical accounts.
    • Revoked them if you're not sure what they are.
    • Explicitly logout after finishing your operations or use Incognito mode.
  • Be skeptical of urgent requests, even from "known" contacts.
  • Have an incident response plan ready BEFORE you need it.
    • If your computer is compromised:
      • Immediately disconnect from network (disable Wi-Fi/unplug ethernet cable) to prevent further data exfiltration.
      • DO NOT reboot or shutdown: this preserves evidence in memory and may prevent malware from establishing persistence.
      • Document everything: take photos of screen, note the time, and any suspicious behavior observed
      • Use a different device to change critical passwords and revoke sessions.
  • Do things that can calm your anxiety.
  • Read Personal Security Checklist.
  • Read An ultimate list of rules any on-chain survivor should follow to stay safe.

Privacy

Credit Card

  • Use different credit cards with different merchants.
    • Some for online shopping.
    • Some for physical payments or Apple Pay/Google Pay.
  • Prefer credit cards over debit cards.
    • Credit card fraud protection is superior because fraudulent charges don't immediately deplete your bank account balance.
  • Set spending limits.

Crypto

  • For large amounts of assets, always store them in hardware wallets or multisig wallets.
  • Use multiple hardware wallets from different vendors: Trezor or Ledger.
    • Some should only hold assets and never interact with DeFi apps.
    • Some are used for trading or farming.
  • Use hardware wallet's hidden wallet with custom passphrase.
  • Always verify transaction details on hardware wallet screens, not just computer screens.
    • Even the Safe UI was spoofed in the infamous Bybit hack.
  • Write your seed phrases on paper or metal, and store them in a physical safe.
    • Keep at least 2 copies in different locations.
    • Never store a hardware wallet's seed phrase digitally, NEVER.
  • Verify backups of your seed phrases every 3 months.
  • Use multisig wallets: Gnosis Safe.
  • Only store a small amount of assets in hot wallets.
    • If you follow this rule, it might be acceptable to store the seed phrase in a password manager.
    • Furthermore, encrypt the seed phrase before storing it.
  • When transferring tokens to a new address, always send a small amount first, and make sure you can transfer them out.
    • It may waste gas, but it's better than losing funds.
  • Add addresses to contacts or whitelists.
  • Always approve tokens with the exact amount, never use infinite (type(uint256).max) approval.
    • It may waste gas, but it's better than losing funds.
  • Always check the slippage setting before swapping.
  • Review your token approvals regularly: Revoke.cash.
    • Before revoking an approval, you should check the original approve() tx is initiated by you.
    • Attackers can create a fake ERC-20 token and set allowance for you.
  • Signing could be dangerous.
    • If it's a clear, human-readable message, it's probably safe to sign.
    • If it contains a large amount of data, read carefully before signing.
    • If the message starts with 0x, just don't sign.
    • Especially, there are "permit" signatures.
  • Use browser extensions or wallets that can simulate/preview transactions.
  • Learn how to decode a transaction.
  • Use Etherscan's Watch List to monitor your account activities.
    • Though the notification might be a bit delayed, it's not real-time.
  • Website (domain name or frontend code) can be hacked as well, even if smart contracts are secure.
  • Read Blockchain Dark Forest Selfguard Handbook. <- HIGHLY RECOMMENDED!

macOS

  • Use an application firewall and network monitor: Little Snitch.
  • Use an antivirus software: Bitdefender Antivirus.
  • Turn on Firewall.
    • System Settings > Network > Firewall > Options > Block all incoming connections
  • Turn on FileVault which provides full disk encryption.
    • System Settings > Privacy & Security > FileVault
  • Power off your computer when not in use, in order for the disk to be encrypted.
  • Automatically lock your screen when idle.
    • System Settings > Lock Screen > Require password after screen saver begins or display is turned off
  • Set one of Hot Corners to "Lock Screen" and always trigger it when you're away from the keyboard.
    • System Settings > Desktop & Dock > Hot Corners
  • Disable AirDrop and Handoff.
    • System Settings > General > Airdrop & Handoff
  • Exclude sensitive folders from Spotlight.
    • System Settings > Siri & Spotlight > Spotlight Privacy
  • Don't use any apps that can read your clipboard or what you type.
  • Don't use third-party input tools if possible.
  • Create separate browser profiles for different use cases.
    • One for daily activities.
    • One for financial activities, don't install any extensions other than the password manager.
    • Use Incognito mode.
    • Even better: use an isolated computer.
  • The fewer browser extensions installed, the better.
    • Carefully review requested permissions when installing/upgrading browser extensions.
    • Be aware of developers might sell their extension to someone else.
  • Disable Chrome's Preload pages.
    • Chrome > Settings > Performance > Preload pages
  • Install OS security patches as soon as possible.
  • Use Dangerzone if you're working with PDFs.
  • Read macOS Security and Privacy Guide.

iOS

  • Enable Data Protection (Erase all data after 10 failed passcode attempts).
    • Settings > Touch ID & Passcode > Erase Data
  • Change the default PIN of your SIM card.
    • Settings > Cellular > SIM PIN > Change PIN
  • Disable Predictive Text.
    • Settings > General > Keyboards > Predictive
    • Settings > General > Transfer or Reset iPhone > Reset > Reset Keyboard Dictionary
  • Turn off AirDrop.
  • Don't use third-party keyboard apps.
    • These apps will be able to access everything you type: passwords, messages, search terms, etc.
  • Restart your device regularly, ex: once a week.
  • Rapidly press the side button 5 times to enter Emergency SOS mode when needed.
    • Under Emergency SOS mode, your passcode is required to re-enable Touch ID or Face ID.
    • Use it when your device is about to be taken away.
  • Read Telegram & Discord Security Best Practices.
  • Read Privacy Guides - iOS Overview.

Developer

  • Always create API keys with minimum permissions and set a short expiration time if possible.
  • Create distinct API keys for different purposes, services, or machines.
    • Deactivate the API key if you're not using it.
  • Avoid storing credentials in plain text on disk, such as in .env files or ~/.aws/credentials.
    • Instead, store them in 1Password Environments and source them with 1Password CLI.
  • If you're unsure, run the program inside a non-root Docker container.
  • The fewer IDE/editor plugins installed, the better.
  • Be aware of Supply Chain Attack.
    • Run tools like npm audit or pip-audit to check.
  • Enable security-related features on your GitHub repos.
  • Sign your Git commits.

Wi-Fi

  • Avoid using Wi-Fi routers and IoT devices made in China if possible.
    • Due to documented security vulnerabilities and potential mandatory backdoor requirements.
  • Must change the default username/password of your devices.
  • Create a dedicated Wi-Fi network (guest network) for IoT devices.
  • Keep your device firmware up-to-date.
  • Use WPA3-Personal if possible.
  • Disable remote access on your router.
    • If you really want to visit your router's management console through the Internet, set IP whitelist at least.
  • Disable WPS (Wi-Fi Protected Setup) which is vulnerable to brute-force attack.
  • Avoid using public Wi-Fi.

Physical

  • Be cautious when plugging USB devices into your computer.
    • Don't charge devices from your computer if possible.
  • Be vigilant for key loggers.
    • Bring your own keyboard and USB hub when necessary.
  • Cover your laptop's camera with a sticky note.
  • Use certified and well-protected extension cords.
  • Get fire and earthquake insurance for your house.
  • Shred or redact sensitive documents.
    • Instead of simply disposing of them in the trash.

Personal

  • Never share where you live or post photos that could potentially reveal your location.
    • Like a photo of the view from your window, such data can be exploited via OSINT (Open-Source INTelligence).
    • If you really want to share where you've been (such as during travel), only post them after you're back home.
  • Don't reveal information during "inbound" calls.
    • Only share sensitive data during communications that you initiate.
  • Be aware that even if you take all precautions, you may still be vulnerable to a $5 wrench attack.
    • So keep things low-key.

And don't forget: security is always a trade-off.