Source Update

This commit is contained in:
Christer Warén 2024-04-28 06:08:57 +03:00
parent 824ca7168c
commit 28aed09fd1
6 changed files with 120 additions and 20 deletions

View File

@ -18,6 +18,8 @@ wxItalic=$(tput sitm)
wxBold=$(tput bold) wxBold=$(tput bold)
wxNormal=$(tput sgr0) wxNormal=$(tput sgr0)
declare -Ax config
{{ FUNCTIONS }} {{ FUNCTIONS }}
{{ COMMANDS }} {{ COMMANDS }}

View File

@ -1,8 +1,20 @@
wx-ssh() { wx-ssh() {
wx-login wx-login
case $1 in
sign)
wx-ssh-sign
;;
config)
wx-ssh-config
;;
*)
echo -n "$wxItalic" echo -n "$wxItalic"
echo " >> SSH << " echo " >> SSH << "
echo -n "$wxNormal"; echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
wx-stop
;;
esac
} }

View File

@ -1,6 +1,7 @@
wx-ssh-config(){ wx-ssh-config(){
echo -n "$wxItalic" echo -n "$wxItalic"
echo " >> SSH : Config << " echo " >> SSH << "
echo -n "$wxNormal" echo " Config "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
} }

View File

@ -1,6 +1,40 @@
wx-ssh-sign(){ wx-ssh-sign(){
echo -n "$wxItalic" echo -n "$wxItalic"
echo " >> SSH : Certificates << " echo " >> SSH << "
echo " Sign "
echo -n "$wxNormal" echo -n "$wxNormal"
echo "------------------------------" echo "------------------------------"
NAME=warengroup
ROLE=sysadmin
PRINCIPALS=sysadmin
TTL=3600
if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]]
then
echo "$NAME/$ROLE"
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1
fi
NAME=cwinfo
ROLE=sysadmin
PRINCIPALS=sysadmin
TTL=3600
if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]]
then
echo "$NAME/$ROLE"
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1
fi
NAME=cwchristerw
ROLE=sysadmin
PRINCIPALS=sysadmin
TTL=3600
if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]]
then
echo "$NAME/$ROLE"
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1
fi
} }

View File

@ -4,7 +4,7 @@ wx-login() {
echo -n "$wxNormal"; echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
ORG=$2 ORG=$1
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]; then if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]; then
wx-stop wx-stop
@ -92,7 +92,7 @@ wx-login() {
if [[ $VAULT_STATUS -eq 200 ]] if [[ $VAULT_STATUS -eq 200 ]]
then then
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 302 ]] if [[ $IDM_STATUS -eq 301 ]]
then then
echo -n $wxBold echo -n $wxBold
echo -n $ORG echo -n $ORG
@ -138,8 +138,8 @@ wx-login() {
wx-stop wx-stop
fi fi
fi fi
echo ""
config[${ORG}]=$VAULT_LOGIN
wx-start wx-start
else else
echo -n $wxBold echo -n $wxBold
@ -171,6 +171,7 @@ wx-login() {
wx-stop wx-stop
fi fi
config[${ORG}]=$VAULT_LOGIN
wx-start wx-start
fi fi
else else

62
wx
View File

@ -18,13 +18,15 @@ wxItalic=$(tput sitm)
wxBold=$(tput bold) wxBold=$(tput bold)
wxNormal=$(tput sgr0) wxNormal=$(tput sgr0)
declare -Ax config
wx-login() { wx-login() {
echo -n "$wxItalic" echo -n "$wxItalic"
echo " >> Login << " echo " >> Login << "
echo -n "$wxNormal"; echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
ORG=$2 ORG=$1
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]; then if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]; then
wx-stop wx-stop
@ -112,7 +114,7 @@ wx-login() {
if [[ $VAULT_STATUS -eq 200 ]] if [[ $VAULT_STATUS -eq 200 ]]
then then
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 302 ]] if [[ $IDM_STATUS -eq 301 ]]
then then
echo -n $wxBold echo -n $wxBold
echo -n $ORG echo -n $ORG
@ -158,8 +160,8 @@ wx-login() {
wx-stop wx-stop
fi fi
fi fi
echo ""
config[${ORG}]=$VAULT_LOGIN
wx-start wx-start
else else
echo -n $wxBold echo -n $wxBold
@ -191,6 +193,7 @@ wx-login() {
wx-stop wx-stop
fi fi
config[${ORG}]=$VAULT_LOGIN
wx-start wx-start
fi fi
else else
@ -282,10 +285,22 @@ wx-settings() {
wx-ssh() { wx-ssh() {
wx-login wx-login
case $1 in
sign)
wx-ssh-sign
;;
config)
wx-ssh-config
;;
*)
echo -n "$wxItalic" echo -n "$wxItalic"
echo " >> SSH << " echo " >> SSH << "
echo -n "$wxNormal"; echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
wx-stop
;;
esac
} }
wx-welcome() { wx-welcome() {
@ -297,16 +312,51 @@ wx-welcome() {
wx-ssh-config(){ wx-ssh-config(){
echo -n "$wxItalic" echo -n "$wxItalic"
echo " >> SSH : Config << " echo " >> SSH << "
echo -n "$wxNormal" echo " Config "
echo -n "$wxNormal";
echo "------------------------------" echo "------------------------------"
} }
wx-ssh-sign(){ wx-ssh-sign(){
echo -n "$wxItalic" echo -n "$wxItalic"
echo " >> SSH : Certificates << " echo " >> SSH << "
echo " Sign "
echo -n "$wxNormal" echo -n "$wxNormal"
echo "------------------------------" echo "------------------------------"
NAME=warengroup
ROLE=sysadmin
PRINCIPALS=sysadmin
TTL=3600
if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]]
then
echo "$NAME/$ROLE"
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1
fi
NAME=cwinfo
ROLE=sysadmin
PRINCIPALS=sysadmin
TTL=3600
if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]]
then
echo "$NAME/$ROLE"
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1
fi
NAME=cwchristerw
ROLE=sysadmin
PRINCIPALS=sysadmin
TTL=3600
if [[ -f "$HOME/.ssh/keys/$NAME-ed25519" ]]
then
echo "$NAME/$ROLE"
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config[$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME-ed25519.pub)\", \"valid_principals\": \"$PRINCIPALS,$USER\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME-ed25519.sig 2>&1
fi
} }