-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use AAD Cluster with non-admin users #25
Comments
The alternate way is to use Would you be willing to a raise a PR to fix this btw? You could introduce a new input called |
Oh! If that's the case you could consider just using azure/login action and then running a script action.. i.e. |
@DS-MS yea that is what I also tried. This is what I have tried so far.
Which runs successfully and produces the following trace.
But as you can see it says
-Error: Error: Cluster context not set. Use k8ssetcontext action to set cluster context I can't seem to find any Microsoft example of this scenario. All examples I find assume that the deploying action SP has admin rights to the cluster. We as a enterprise solution are trying to restrict access to the namespace level, as @jorik mentioned to, and have actions from product teams deploy to their namespaces and not other product teams namespaces. As in practice we are using a cluster as a common platform for a set of products. You mention it might be simpler to just fix the issue on this action, can you provide some more detail. As I think we want to make use of this action. |
I meant more like : - name: Azure Login
uses: Azure/login@v1
with:
creds: "${{ secrets.AZURE_CREDENTIALS }}"
- run: az aks get-credentials -n <cluster-name> -g <resource-group>
- uses: Azure/[email protected]
with:
namespace: '<namespace>'
manifests: |
deployment.yaml
service.yaml
images: '<contianerstore>.azurecr.io/<image>:v1.0.0'
kubectl-version: 'latest'
Also this is just a workaround, @Ganeshrockz is currently working on adding this. 😄 |
@DS-MS yes, that is what I tired as well, and I get that context error. I opened #31 for feedback but if @Ganeshrockz is already on it I can close it. Any other help you can give me as a work around? |
@molinamelendezj - name: Azure Login
uses: azure/login@v1
with:
creds: "${{ secrets.AZURE_CREDENTIALS }}"
- name: Set KUBECONFIG env variable
run: echo "KUBECONFIG=${RUNNER_TEMP}/kubeconfig-$(date +%s)" >> $GITHUB_ENV
- name: Set AKS cluster context
run: |
az aks get-credentials -n <cluster-name> -g <resource-group> -f ${KUBECONFIG} Based on https://github.com/Azure/aks-set-context/blob/releases/v1/src/login.ts#L53. |
@dnovvak your suggestions looked promising, but I get the following error:
I also adjusted your suggestion as it seems its a - name: List files in runner.temp
working-directory: ${{ runner.temp }}
run: find ./ -type f And confirmed kubeconfig file is not there. I think the |
That is really interesting because it works for me.
The name of kubeconfig file is not very important here since we use For sure the kubeconfig file should be created by I use non-admin user for CI/CD and have AKS cluster configured with AAD and Azure RBAC. Here is complete job definition for my case, maybe this will help: deploy-to-aks:
name: Deploy to AKS
needs: build-image
runs-on: ubuntu-latest
permissions:
contents: read
env:
NAMESPACE: foo-ns
SECRET: my-image-pull-secret
APP: myApp
REGISTRY: ghcr.io
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Construct image ref
run: echo "IMAGE_REF=${REGISTRY}/${GITHUB_REPOSITORY,,}/${APP}:$(cat ${APP}/VERSION)" >> $GITHUB_ENV
# this step is required for me because of AAD and Azure RBAC integration
- name: Set up kubelogin for non-interactive login
run: |
curl -LO https://github.com/Azure/kubelogin/releases/download/v0.0.9/kubelogin-linux-amd64.zip
sudo unzip -j kubelogin-linux-amd64.zip -d /usr/local/bin
rm -f kubelogin-linux-amd64.zip
kubelogin --version
- name: Azure Login
uses: azure/login@v1
with:
creds: "${{ secrets.AZURE_CREDENTIALS }}"
- name: Set KUBECONFIG env variable
run: echo "KUBECONFIG=${RUNNER_TEMP}/kubeconfig-$(date +%s)" >> $GITHUB_ENV
- name: Set AKS cluster context
run: |
az aks get-credentials -n <cluster-name> -g <resurce-group> -f ${KUBECONFIG}
kubelogin convert-kubeconfig -l azurecli # this is required for me because of AAD and Azure RBAC integration
- name: Create image pull secret
uses: azure/k8s-create-secret@v1
with:
container-registry-url: ${{ env.REGISTRY }}
container-registry-username: ${{ secrets.REGISTRY_USER }}
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
secret-name: ${{ env.SECRET }}
namespace: ${{ env.NAMESPACE }}
arguments: --force true
- name: Deploy to AKS
uses: azure/k8s-deploy@v1
with:
manifests: |
${{ env.APP }}/k8s/configmap.yaml
${{ env.APP }}/k8s/deployment.yaml
images: ${{ env.IMAGE_REF }}
imagepullsecrets: ${{ env.SECRET }}
namespace: ${{ env.NAMESPACE }} |
@dnovvak ! thanks man. This got further now, and we also use non-admin user for CI/CD and have AKS cluster configured with AAD and Azure RBAC so looks like you have help even more than I expected 😄 I need to fix some access to my image store, but looks like the action is connecting and authin' now. you rock. Thanks! |
JFYI, @Ganeshrockz has raised this PR to fix this: #32 You can test it out by using ref |
@DS-MS @DS-MS and @Ganeshrockz actually spoke to soon. seems my aks-deploy hung. I think there is more to cosider since I'm using AAD and RBAC like @dnovvak, and looks like he had that other workaround using the |
@molinamelendezj Can you try rerunning the workflow again with the action targeting the same branch ( |
@Ganeshrockz the action won't run now. |
@molinamelendezj could you dump the error log here? |
@DS-MS here it is below. I had to turn on debugging on the workflow, I think this is an unhandled exception that is why I can't see anything. Is there a missing permission we need on our SP for this to work as expected? Also as I mention in my #31 there is a new endpoint and this azure management api endpoint is being deprecated. |
@molinamelendezj I was just testing things with the newer API which AKS team has provided; things seem to work seamlessly for me. I noticed in your earlier logs, kubectl requested you to explicitly authenticate using a device code. Is your cluster integrated with AAD? One alternative to that is you could provide admin privileges to the SPN you are using within that cluster to help you use it in automation. |
@DS-MS yes we are using AAD. We do not want to use admin privileges on the SP. we are using the cluster as a shared platform within the enterprise, we don't want product teams being able to deploy to other namespaces either by mistake or on purpose. @dnovvak's work around above works just fine, would be nice to fix the action to handle the AAD case. |
Thank you, thank you, thank you @dnovvak for taking the time to share your solution, it really helped me. It would be nice if the action could handle this case. |
This issue is idle because it has been open for 14 days with no activity. |
Hi, is this feature merged in v1? I am getting below message : |
I updated this action to use this technique for v2.0.
It was never merged into v1, v2.0 should be used instead. |
Thanks @OliverMKing. Will try with v2.0. 👍 |
The action "azure/[email protected]" runs ok with a non-admin service principal but the action that follows "Azure/[email protected]" fails as it seems like it is trying to do an interactive login: "(https://github.com/Azure/aks-baseline-automation/runs/5162795080?check_suite_focus=true#step:5:33)31 1658 azure.go:163] Failed to acquire a token: failed acquiring new token: waiting for device code authentication to complete: autorest/adal/devicetoken: Error while retrieving OAuth token: Code Expired Do we have to use kubelogin somehow to get around this issue: https://docs.microsoft.com/en-us/azure/aks/managed-aad#non-interactive-sign-in-with-kubelogin ? |
@bahramr try adding the following steps from @dnovvak. - name: Set up kubelogin for non-interactive login
run: |
curl -LO https://github.com/Azure/kubelogin/releases/download/v0.0.9/kubelogin-linux-amd64.zip
sudo unzip -j kubelogin-linux-amd64.zip -d /usr/local/bin
rm -f kubelogin-linux-amd64.zip
kubelogin --version
- name: Convert kubeconfig
run: |
kubelogin convert-kubeconfig -l azurecli |
This issue is idle because it has been open for 14 days with no activity. |
The most recent changes @tbarnes94 should fix this but we'll need a new release cut to publish it. The README will need updating as well since the new parameters aren't in v2.0. |
Created a new release. V2.2, V2 (latest in V2), and subsequent releases have this fix. |
Hello,
We are trying to use this action with a Service Principle that only has access to a single namespace in our AKS cluster, but we're getting these errors:
I can see in the code that the clusterAdmin role is hardcoded. Is there a way to make this configurable? Or is there an alternative action we can use to log in to AKS?
The text was updated successfully, but these errors were encountered: