Repository navigation
Description
I was the last weeks hardly working on our backup solution using volsync and restic using azure workload identity in our AKS environment.
I found, that restic can do so since: restic/restic#4029
But there are some missing values in volsync to archive the full flow with managed identites with a AKS setup.
There are three env variables missing:
AZURE_TENANT_ID
AZURE_CLIENT_ID
AZURE_FEDERATED_TOKEN_FILE
AZURE_TENANT_ID and AZURE_CLIENT_ID have to be configured by the user and must be transferred to the scheduling pod from the restic_config secret.
The AZURE_FEDERATED_TOKEN_FILE points to the service account token in the pod and could be fixed in the backup pod template like:
- name: AZURE_FEDERATED_TOKEN_FILE
value: "/var/run/secrets/kubernetes.io/serviceaccount/token"
What is the value to the end user? (why is it a priority?)
The main value to use workload identity is, that u don't have any passwords or token in Kubernetes at all. Our CISO would love to see that.
How will we know we have a good solution? (acceptance criteria)
Backup in AKS without credentials
Additional context
I'll try to make a pull request, especially for the azure setup documentation
Workaround
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: inject-env-from-sa-label
spec:
rules:
- name: inject-backup-mode
match:
any:
- resources:
kinds:
- Pod
selector:
matchLabels:
app.kubernetes.io/created-by: volsync
context:
- name: clientID
apiCall:
urlPath: "/api/v1/namespaces/{{request.namespace}}/serviceaccounts/backup"
jmesPath: "metadata.annotations.\"azure.workload.identity/client-id\""
- name: tenantID
variable:
value: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
- name: tokenFile
variable:
value: "/var/run/secrets/kubernetes.io/serviceaccount/token"
mutate:
patchStrategicMerge:
spec:
containers:
- (name): "*"
env:
- name: AZURE_CLIENT_ID
value: "{{ clientID }}"
- name: AZURE_TENANT_ID
value: "{{ tenantID }}"
- name: AZURE_FEDERATED_TOKEN_FILE
value: "{{ tokenFile }}"
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
tesshuflower commentedon Feb 9, 2026
@sybnex This doesn't appear to be documented in restic, if you can help with updating restic docs (maybe that is what you mean by opening a PR?) that would be great.
It should be simple for us to pass through and AZURE_TENANT_ID if they're specified in the restic config, however when it comes to
AZURE_FEDERATED_TOKEN_FILE, I'm not sure when this needs to be setup.Can we assume if
AZURE_CLIENT_IDandAZURE_TENANT_IDare set thatAZURE_FEDERATED_TOKEN_FILEshould point to/var/run/secrets/kubernetes.io/serviceaccount/token?tesshuflower commentedon Feb 10, 2026
Actually if we want to be consistent with the way we've handled other credentials, perhaps it would be better if we model
AZURE_FEDERATED_TOKEN_FILEas we did withGOOGLE_APPLICATION_CREDENTIALS. Essentially we allow setting it as text in the restic secret and volsync will mount this as a file and point the env var to it.See the note about
GOOGLE_APPLICATION_CREDENTIALSheresybnex commentedon Feb 16, 2026
Hi,
Restic is using the Azure SDK get a token for the connection. The SDK has like 5 possibilites how archive this. Volsync uses the direct path to the backend storage only and forward this info over the
restic-configto the restic pod =>volsync/internal/controller/mover/restic/mover.go
Line 461 in a4be672
An example secret in my case would look like this:
AZURE_TENANT_ID and AZURE_CLIENT_ID must be configurable.
But AZURE_FEDERATED_TOKEN_FILE can be fixed by the given path. Azure uses the Kubernetes Service Account to validate the Managed Identities in Azure (https://learn.microsoft.com/en-us/azure/aks/workload-identity-deploy-cluster?tabs=new-cluster) to get a Token to access the Backend Storage like Azure Blob. Restic is aware of all off those by using the Azure SDK and I tested it successfully with the workaorund above.
PS: The docu in restic is there, but just very small => https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html#microsoft-azure-blob-storage
Do u need any more informations?
tesshuflower commentedon Feb 17, 2026
@sybnex I can add these additional AZURE variables, but for
AZURE_FEDERATED_TOKEN_FILEwe'd like to model it like we did previously forGOOGLE_APPLICATION_CREDENTIALS(see explanation of GOOGLE_APPLICATION_CREDENTIALS in the NOTE in this section: https://volsync.readthedocs.io/en/stable/usage/restic/index.html#specifying-a-repository)Do you see any issue with that? It means in your restic secret,
AZURE_FEDERATED_TOKEN_FILEwould be slightly different, you'd need to set it to the string value of the token file itself. VolSync would then write this to a file, and point the env var to that file location (in the mover pod itself). This has the advantage of being consistent with other credentials, and not needing to alter your service account - but perhaps this causes some issue with automatic token renewal?sybnex commentedon Feb 19, 2026
I see u point.
But the content from
/var/run/secrets/kubernetes.io/serviceaccount/tokenis automatically generated by kubernetes itself. It is has the token generated from a Kubernetes Service Account which is used by the deployment/pod during the runtime => https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#use-the-default-service-account-to-access-the-api-serverSo it would be impossible to read it during the run and forward the content at the same time to this variable, as the token is created during the startup of the pod.
Volsync could just use this given string as default to use the already mounted token from kubernetes. This works acutally only in this case together with the azure sdk and managed identites with the federation solution. Check this Article for more details in the fow: https://paulyu.dev/article/cross-tenant-workload-identity-on-aks/
Anyway. It would be great to implement it as far as you can.
tesshuflower commentedon Mar 5, 2026
@sybnex I think we will just pass through the env vars directly then from the secret, just to keep it simple (and handled the same way as most other env vars).
so it'll be up to you to set
AZURE_FEDERATED_TOKEN_FILE: "/var/run/secrets/kubernetes.io/serviceaccount/token"in your secret, as per your example above.restic env vars for azure workload identity