Skip to content

Commit

Permalink
feat: Adding azure relogin feature
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeluxe authored and dploeger committed Jun 11, 2024
1 parent 08842d7 commit a8e9b51
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ To start a new session in the CloudControl context, run `createSession <token>`

Can be used to connect to infrastructure in the Azure cloud. Because we're using a container,
a device login will happen, requiring the user to go to a website, enter a code and login.
This only happens once during initialization phase.

The azure login tokens usually expire after some time. You can run the `azure-relogin` script
(located in ~/bin, thus available without path) to re-execute the same login commands as the
initialization process does.

#### Configuration

Expand Down Expand Up @@ -774,7 +777,3 @@ flowchart TD
click F "https://github.com/dodevops/cloudcontrol/blob/develop/.github/workflows/test.yml" "Test workflow"
click H "https://github.com/dodevops/cloudcontrol/blob/develop/.github/workflows/release.yml" "Release workflow"
```mermaid
github.com/dodevops/cloudcontrol/blob/develop/.github/workflows/release.yml" "Release workflow"
```mermaid
maid
1 change: 1 addition & 0 deletions feature/kubernetes/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ EOF
fi

echo "#!/bin/sh" > ~/bin/k8s-relogin
echo "~/bin/azure-relogin" >> ~/bin/k8s-relogin

AZ_DO_KUBELOGIN_CONVERT="${AZ_USE_ARM_SPI:-false}"
for CLUSTER in $(echo "${AZ_K8S_CLUSTERS}" | tr "," "\n"); do
Expand Down
5 changes: 4 additions & 1 deletion flavour/azure/flavour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ title: "[Azure](https://github.com/dodevops/cloudcontrol/pkgs/container/cloudcon
description: |
Can be used to connect to infrastructure in the Azure cloud. Because we're using a container,
a device login will happen, requiring the user to go to a website, enter a code and login.
This only happens once during initialization phase.
The azure login tokens usually expire after some time. You can run the `azure-relogin` script
(located in ~/bin, thus available without path) to re-execute the same login commands as the
initialization process does.
configuration:
- "Environment AZ_SUBSCRIPTION: The Azure subscription to use in this container"
- "Environment AZ_TENANTID: The Azure tenant id to log into (optional)"
Expand Down
17 changes: 17 additions & 0 deletions flavour/azure/flavourinit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ then
exit 1
fi

echo "#!/bin/sh" > ~/bin/azure-relogin
cat <<EOF >>~/bin/azure-relogin
AZ_ACCOUNT_SHOW_OUTPUT="$(az account show 2>&1)"
if [ $? -eq 0 ]; then
echo "Azure login still valid, no relogin required"
exit 0
else
echo "Azure login expired, relogin required, see following error:"
echo "${AZ_ACCOUNT_SHOW_OUTPUT}"
echo "Performing relogin now..."
fi
EOF
echo az login "${tenantArg[@]}" >> ~/bin/azure-relogin

if [ "X${AZ_SUBSCRIPTION}X" == "XX" ]
then
echo -n "* Subscription: "
Expand All @@ -32,6 +46,9 @@ then
echo "Can not set subscription"
exit 1
fi
echo az account set --subscription "${AZ_SUBSCRIPTION}" >> ~/bin/azure-relogin

chmod +x ~/bin/azure-relogin

echo "Preparing bashrc"
cat <<EOF >>~/.bashrc
Expand Down

0 comments on commit a8e9b51

Please sign in to comment.