The problem is that the OIDC Authorization Code flow was never designed to support this use case, so it doesn’t.
The vault login -method=oidc
command has a hard requirement on running on the same computer as the web browser the user will use to complete the login, and so it is not a tool to be used over an SSH connection.
There are two options I can think of:
One: Complete a Vault OIDC login on a machine where you do have a graphical web browser, and copy/paste the Vault token to the environment on the other side of the SSH connection.
The command vault login
with no -method
directly accepts a Vault token and stores it for future Vault commands.
Two: Implement a custom tool that uses the OIDC Device Code flow to log in.
In this flow, the custom tool makes an HTTP request to the OIDC IdP, and receives a code or new URL containing the code.
It prints an URL to the screen, along with instructions to the user to visit the URL in their browser - either the code is embedded in the URL, or the user is asked to manually type it in. (That is to support cases where copy/paste is impossible - probably not the case here.)
The user proceeds with the login flow in the browser and meanwhile the custom tool polls the OIDC IdP asking whether it is complete yet.
Once the user has completed the login, the custom tool receives the OIDC token on its next poll.
The custom tool then submits the OIDC token (a JWT) to the Vault OIDC/JWT auth method, using a role that is configured in Vault as role_type=jwt
. Vault validates the JWT and exchanges it for a Vault token.
The custom tool then stores the Vault token for the user’s use (e.g. by running vault login $TOKEN
).
Unfortunately the Vault CLI doesn’t support this flow natively, hence the need for a custom tool.