Skip to content

Instantly share code, notes, and snippets.

@wheelerlaw
Last active April 19, 2023 21:52
Show Gist options
  • Save wheelerlaw/3d852c6a0e5122f050e64541101d3aac to your computer and use it in GitHub Desktop.
Save wheelerlaw/3d852c6a0e5122f050e64541101d3aac to your computer and use it in GitHub Desktop.
Golang 1Password CLI error reproduction
# To replicate the issue with running the `op` command directly from a Golang app
Vagrant.configure("2") do |config|
config.vm.box = "generic/fedora37"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "2048"
vb.cpus = "2"
vb.customize ["modifyvm", :id, "--graphicscontroller", "vmsvga"]
end
config.vm.provision "shell", privileged: false, inline: <<~'EOF'
#!/usr/bin/env bash
set -x
sudo dnf update -y
sudo dnf group install -y "Fedora Workstation" --allowerasing
sudo systemctl enable gdm.service
sudo systemctl set-default graphical.target
sudo dnf install -y golang
sudo rpm --import https://downloads.1password.com/linux/keys/1password.asc
sudo sh -c 'echo -e "[1password]\nname=1Password Stable Channel\nbaseurl=https://downloads.1password.com/linux/rpm/stable/\$basearch\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=\"https://downloads.1password.com/linux/keys/1password.asc\"" > /etc/yum.repos.d/1password.repo'
sudo dnf install -y 1password 1password-cli
echo '
package main
import (
"log"
"os/exec"
"os"
"fmt"
)
func main() {
fmt.Println(os.Args)
var opExecutable string
if os.Args[1] == "python" {
opExecutable = "./op.py"
} else if os.Args[1] == "direct" {
opExecutable = "op"
}
op := exec.Command(opExecutable, "item", "list")
op.Stdin = os.Stdin
out, err := op.Output()
if e, ok := err.(*exec.ExitError); ok {
log.Fatal(e, ": ", string(e.Stderr))
}
fmt.Println(string(out))
}
' > ~/main.go
echo '#!/usr/bin/env python3
import subprocess
import sys
subprocess.run(["op"] + sys.argv[1:])
' > ~/op.py
chmod +x ~/op.py
set +x
echo "Now reboot the VM with 'vagrant reload'. Once that is done, log into the VM when it loads (password is 'vagrant'), sign into 1Password"
echo "and configure it to allow connection from the CLI. Then, from the terminal in the VM, run 'op signin'."
echo "To replicate the issue, run 'go run main.go direct'. To run it though Python, run 'go run main.go python'."
EOF
end
@wheelerlaw
Copy link
Author

Updated the Go file to include op.Stdin = os.Stdin on line 43 in response to this comment on said StackOverflow question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment