Forum Discussion

Niels3242's avatar
Niels3242
New Contributor
8 months ago

How to successfully pass 1Password stored SSH key to terminal in VSCode devcontainer?

I have a Rails 8 app which is using devcontainers. On my macOS I have 1Password setup to store my ssh private key and it works as it should from the terminal in the os. Using e.g. ssh commands invokes the authentication prompt from 1password. However, when I am developing the Rails project from the devcontainer attached terminal in VS Code (or in my case Cursor.com, a fork from VS Code), I have the problem, that ssh commands does not invoke 1password prompt. It looks like the whole thing is not really connected as it should. How do I ensure that it works?

My devcontainer config is the standard Rails generates:

// For format details, see https://containers.dev/implementors/json_reference/.
// For config options, see the README at: https://github.com/devcontainers/templates/tree/main/src/ruby
{
"name": "my_app",
"dockerComposeFile": "compose.yaml",
"service": "rails-app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/rails/devcontainer/features/activestorage": {},
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
"ghcr.io/rails/devcontainer/features/postgres-client": {}
},

"containerEnv": {
"CAPYBARA_SERVER_PORT": "45678",
"SELENIUM_HOST": "selenium",
"DB_HOST": "postgres"
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000, 5432],

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://containers.dev/implementors/json_reference/#remoteUser.
// "remoteUser": "root",

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bin/setup --skip-server"
}

2 Replies

  • Niels3242's avatar
    Niels3242
    New Contributor

    Thanks for the suggestions. Yes SSH_AUTH_SOCK is set as it should. I looked at the links, but no luck unfortunately. Same issue still

  • Michael_Mercuri's avatar
    Michael_Mercuri
    Frequent Contributor

    I cannot answer from direct experience since I'm not using VSCode devcontainers, but it sounds like it's a communication issue with 1Password's SSH agent from inside the devcontainer.

    Is the SSH_AUTH_SOCK environment variable set (in your shell running in macOS terminal)?

    Did you see this post which may provide some hints?
    https://1password.community/discussion/146096/vscode-dev-container-and-ssh

    If you've never configured SSH_AUTH_SOCK or SSH Agent forwarding before, more info here:
    https://developer.1password.com/docs/ssh/agent/forwarding