feat: add WSL2 1Password SSH Agent bridge setup and update README with instructions
This commit is contained in:
@@ -49,6 +49,10 @@
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: Include WSL2 tasks
|
||||
ansible.builtin.import_tasks: tasks/global/wsl.yml
|
||||
when: "'microsoft-standard-WSL2' in ansible_kernel"
|
||||
|
||||
- name: Include Utils tasks
|
||||
ansible.builtin.import_tasks: tasks/global/utils.yml
|
||||
become: true
|
||||
|
@@ -34,4 +34,4 @@
|
||||
mennos-vm: "$DOTFILES_PATH/config/git/gitconfig.mennos-server"
|
||||
dotfiles-test: "$DOTFILES_PATH/config/git/gitconfig.mennos-server"
|
||||
tags:
|
||||
- symlinks
|
||||
- symlinks
|
||||
|
47
config/ansible/tasks/global/wsl.yml
Normal file
47
config/ansible/tasks/global/wsl.yml
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
- name: WSL2 1Password SSH Agent Bridge
|
||||
block:
|
||||
- name: Ensure required packages are installed for 1Password sock bridge
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
# 1Password (WSL2 required package for sock bridge)
|
||||
- socat
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: Ensure .1password directory exists in home
|
||||
ansible.builtin.file:
|
||||
path: "{{ ansible_env.HOME }}/.1password"
|
||||
state: directory
|
||||
mode: '0700'
|
||||
|
||||
- name: Create .agent-bridge.sh in home directory
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ ansible_env.HOME }}/.agent-bridge.sh"
|
||||
mode: '0755'
|
||||
content: |
|
||||
# Code extracted from https://stuartleeks.com/posts/wsl-ssh-key-forward-to-windows/
|
||||
|
||||
# (IMPORTANT) Create the folder on your root for the `agent.sock` (How mentioned by @rfay and @Lochnair in the comments)
|
||||
mkdir -p ~/.1password
|
||||
|
||||
# Configure ssh forwarding
|
||||
export SSH_AUTH_SOCK=$HOME/.1password/agent.sock
|
||||
# need `ps -ww` to get non-truncated command for matching
|
||||
# use square brackets to generate a regex match for the process we want but that doesn't match the grep command running it!
|
||||
ALREADY_RUNNING=$(ps -auxww | grep -q "[n]piperelay.exe -ei -s //./pipe/openssh-ssh-agent"; echo $?)
|
||||
if [[ $ALREADY_RUNNING != "0" ]]; then
|
||||
if [[ -S $SSH_AUTH_SOCK ]]; then
|
||||
# not expecting the socket to exist as the forwarding command isn't running (http://www.tldp.org/LDP/abs/html/fto.html)
|
||||
echo "removing previous socket..."
|
||||
rm $SSH_AUTH_SOCK
|
||||
fi
|
||||
echo "Starting SSH-Agent relay..."
|
||||
# setsid to force new session to keep running
|
||||
# set socat to listen on $SSH_AUTH_SOCK and forward to npiperelay which then forwards to openssh-ssh-agent on windows
|
||||
(setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
tags:
|
||||
- wsl
|
||||
- wsl2
|
Reference in New Issue
Block a user