From 9a7fe730147eb42e0824eb88b52bffa0062f7eec Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Sat, 19 Oct 2019 12:36:29 +0200 Subject: [PATCH] bw password muckery --- .config/systemd/user/ssh-agent.service | 2 +- .zshrc | 9 +++++-- bin/bw-ssh-add | 4 ++- bin/pwenv | 37 +++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/.config/systemd/user/ssh-agent.service b/.config/systemd/user/ssh-agent.service index 36eff44..02c9020 100644 --- a/.config/systemd/user/ssh-agent.service +++ b/.config/systemd/user/ssh-agent.service @@ -5,7 +5,7 @@ Description=SSH key agent Type=forking Environment=SSH_AUTH_SOCK=%h/.ssh/ssh_auth_sock ExecStartPre=/usr/bin/rm -f $SSH_AUTH_SOCK -ExecStart=/usr/bin/ssh-agent -a $SSH_AUTH_SOCK -t 3600 +ExecStart=/usr/bin/ssh-agent -a $SSH_AUTH_SOCK -t 18200 [Install] WantedBy=default.target diff --git a/.zshrc b/.zshrc index a980fdc..ce0e720 100644 --- a/.zshrc +++ b/.zshrc @@ -11,7 +11,7 @@ export PATH=$HOME/bin:$PATH:/bin:/sbin:/usr/sbin:/usr/local/sbin export EDITOR=nvim #export DISPLAY=:0 -export GDK_SCALE=2 +export GDK_SCALE=1.5 fpath=(~/.zsh/functions $fpath) @@ -182,7 +182,9 @@ function prompt_command { # alias zshconfig="mate ~/.zshrc" # alias ohmyzsh="mate ~/.oh-my-zsh" -alias ls='ls --color=auto --group-directories-first --human-readable --almost-all' +# alias ls='ls --color=auto --group-directories-first --human-readable --almost-all' +alias ls=exa +alias bat=bat --theme=ansi-light bindkey -e bindkey "^[[A" history-substring-search-up @@ -249,6 +251,9 @@ command -v helm >/dev/null 2>&1 && source <(helm completion zsh) command -v ark >/dev/null 2>&1 && source <(ark completion zsh) command -v stern >/dev/null 2>&1 && source <(stern --completion zsh) +# Flux +export FLUX_FORWARD_NAMESPACE=flux + [ -f /usr/share/bash-completion/completions/aws ] && source /usr/share/bash-completion/completions/aws [ -f /opt/google-cloud-sdk/completion.zsh.inc ] && source /opt/google-cloud-sdk/completion.zsh.inc diff --git a/bin/bw-ssh-add b/bin/bw-ssh-add index 112a270..c067384 100755 --- a/bin/bw-ssh-add +++ b/bin/bw-ssh-add @@ -1,11 +1,13 @@ #!/bin/bash set -eu -AUTO_LOCK=900 +AUTO_LOCK=3600 BW_SESSION= exit_error() { echo "$2" + keyctl purge user bw_master || true + keyctl purge user bw_session || true exit "$1" } diff --git a/bin/pwenv b/bin/pwenv index 408e09d..2418d89 100755 --- a/bin/pwenv +++ b/bin/pwenv @@ -1,7 +1,42 @@ #!/bin/bash set -eu +purge=0 +ttl=259200 + +usage() { echo "Usage: $0 [-t SECONDS] [-f]" 1>&2; exit 1; } + +while getopts ":ft:" o; do + case "${o}" in + f) + purge=1 + ;; + t) + ttl=${OPTARG} + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) + var="$1" shift -exec env ${var}=$(systemd-ask-password --accept-cached --keyname="pwenv.${var}" "${var}: ") "$@" +if [ -z "${var}" ]; then + usage +fi + +function get_password() { + key="pwenv.${var}" + if [ "${purge}" == "1" ]; then + keyctl purge user ${key} 2>&1 >>/dev/null || true + fi + out=$(systemd-ask-password --accept-cached --keyname="${key}" "${var}:") + key_id=$(keyctl request user ${key} 2>/dev/null) + keyctl timeout $key_id $ttl + echo $out +} + +exec env ${var}=$(get_password) "$@"