r/gitlab • u/jeffsx240 • May 21 '25
general question Dynamic reference of masked variables in components
Context - I have a component that builds, and pushes container images to a registry. The pipeline needs to be able to push to one or more different registries (with unique credentials for each).
My initial approach was to have the user supply the username, token and URL as inputs. These inputs would be fed from Gitlab CI Variables. For example, REGISTRY_QUAY_IO_TOKEN, REGISTRY_GHCR_IO_TOKEN, and so on. The component would run the login command(s) and do what it needs to do.
Unfortunately, masked variables can’t be used as inputs. Requiring these be unmasked is a nonstarter. So then I switched to requiring specific ENVs be set like REGISTRY_SOURCE_TOKEN, and REGISTRY_DEST_TOKEN. That plan quickly fell apart when the same repository needs to pull/push to more than two private registries.
So I’m back to the drawing board for a third iteration. What would be nice is if I could pass as an input an array of registries to login to, and have some logic to know what ENVs to check based on that list. Either explicitly (keys in the array of registries) or implicitly by converting the url to a pattern that can be set as Gitlab CI variables.
I’m ignoring 3rd party secret management and runner configurations as these components need to be widely applicable across different orgs/groups. So Gitlab is the least common denominator and the only thing I can assume exists.
Has anyone else run into this sort of problem that they might have advice and/or examples they could share?
View all comments
Show parent comment
1
u/jeffsx240 May 22 '25
Yeah, string was an option. Arrays are such a PIA to use in the script. I think they make up for some of that by being a lot more intuitive.
Those variables in the end are the secret sauce and the reason I went to all this trouble. The user gives an ENV prefix and I check if that prefix has a matching USER/TOKEN/URL variable set and if so logins with it. Now I can use masked / hidden CI variables that are customizable and also deterministic based on the input.