You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Discussion on adding custom resources types to manage tokens, users, groups, projects #395
I am considering adding custom types and providers to manage gitlab internal configs.
What is the best way to interact from a custom type/provider with gitlab?
At the moment I see two ways:
executing gitlab-rails runner
communicate with api
gitlab-rails command
The gitlab-rails command can be run as root user. No further authentication required.
This allows to check existing and add new tokens, users, groups, projects.
But: the command is very slow.
api
Communication with api needs a token.
root token can be managed using gitlab-rails only.
other user tokens can be managed using the root token.
all other resource types will need an autorequire on the gitlab_token type.
But: where to store the root api token itself so it can be used by all other resource types?
In puppet cache dir?
or is it possible to pass a variable from one provider to another one without again running the gitlab-rails command?
I've never really used the gitlab-rails runner command so I had to check it out on our system:
$ time gitlab-rails runner 'puts Rails.env'
production
real 0m44.396s
user 0m36.290s
sys 0m5.594s
This is our production Gitlab (8 CPU/32GB RAM). To be honest, I don't see how this can be successfully integrated. Even if all resource creation requests would share one gitlab-rails runner session this would be to long IMHO.
So from my point of view the only option is the API - even thought that the API token handling might be a manual step.
Regarding the storage location of the token: I don't like to put relevant things in the cache dir. I would prefer to just store it in /etc/gitlab with the restrictive permissions. This might be "ok" because an attacker who can access this file will also be able to just use gitlab-rails runner/console. From a design perspective it would be also nice to store the token in the PuppetDB because in a "classic" web setup this would be the place where state is persistent. Though I don't know how to implement this.
How about the following idea:
gitlab_token type/provider check if the token file exists in /etc/gitlab/.
If the file exists it does not do anything.
If the file is missing, the token will be created using gitlab-rails runner command and written to the file.
This will allow us to do a complete automated setup.
Usage of the gitlab_token type will be optional.
All other types/providers use the token file and API calls.
If using the API, could these types be used to manage projects/groups etc. on gitlab.com ? That might be useful to some people? (In which case you probably don't want to implement instances?? and you shouldn't expect gitlab-rails command to be available?)
For the api settings file, (assuming you don't want to make the credentials parameters of each of the individual resources), you can do confine :exists => '/path/to/api_settings.yaml' in the providers and all types can also have
I'd then probably provide a class that users can use to create this file. eg. the user would do something like...
class { 'gitlab::api_settings':
server => 'https://gitlab.com',
token => Sensitive($my_api_token),
}
gitlab_project { 'my_project':
group => 'some/group',
}
# etc.
(With the gitlab_group type, dunno if groups need to know about their parent groups - perhaps so they can autorequire them?)
Finally, I've used the gitlab gem before with good results. Maybe the provider should make use of this? (The module could offer to install it and the providers can confine themselves based on whether it's installed yet)
@alexjfisher sounds like a good idea. But: where can we receive the API token from? Or how to set the token explicitly?
Using gitlab gem also came into my mind. But the same question: how to set or generate the API token?
The token needs to be provided manually. If you don't want this, you could automate it with a local command as described here. This token would than be saved to e.g. /etc/gitlab/$user-token and loaded by the provider.
I guess for use with gitlab.com it would have to be manually provided, but if using the module to deploy your own gitlab installation, then being able to automatically generate it would be better.
Is there an advantage to using these types/providers instead of the official Gitlab Terraform Provider on gitlab.com? While thinking about it... Is it worth developing custom types/provider at all? What would be the benefit?
Haha.. somehow I miss this issue before developing the gitlab_application_settings resource type here: #468. So I just put its settings to the /etc/puppetlabs/gitlab_provider.json file 🤷🏻♂️. Feel free to comment the PR (it's more or less done, just miss the SSL support).
Biggest issue (not mentioned there) is a token requirement.. I know how to work it around in a VERY WEIRD way, but not sure I'd like to (HINT: look into the rake file in the PR).
Activity
bastelfreak commentedon Nov 8, 2021
@baurmatt can you take a look at well? Do you have any opinions on that topic?
baurmatt commentedon Nov 9, 2021
I've never really used the
gitlab-rails runnercommand so I had to check it out on our system:This is our production Gitlab (8 CPU/32GB RAM). To be honest, I don't see how this can be successfully integrated. Even if all resource creation requests would share one
gitlab-rails runnersession this would be to long IMHO.So from my point of view the only option is the API - even thought that the API token handling might be a manual step.
Regarding the storage location of the token: I don't like to put relevant things in the cache dir. I would prefer to just store it in /etc/gitlab with the restrictive permissions. This might be "ok" because an attacker who can access this file will also be able to just use
gitlab-rails runner/console. From a design perspective it would be also nice to store the token in the PuppetDB because in a "classic" web setup this would be the place where state is persistent. Though I don't know how to implement this.tuxmea commentedon Nov 9, 2021
@baurmatt many thanks for your feedback.
How about the following idea:
gitlab_token type/provider check if the token file exists in /etc/gitlab/.
If the file exists it does not do anything.
If the file is missing, the token will be created using gitlab-rails runner command and written to the file.
This will allow us to do a complete automated setup.
Usage of the gitlab_token type will be optional.
All other types/providers use the token file and API calls.
baurmatt commentedon Nov 9, 2021
Sounds good! Looking forward to the implementation! :)
tuxmea commentedon Nov 9, 2021
@baurmatt
List of types and properties:
baurmatt commentedon Nov 9, 2021
@tuxmea You probably want
email - Stringforgitlab_useras well.Beside this it looks like a good start! 👍
alexjfisher commentedon Nov 9, 2021
If using the API, could these types be used to manage projects/groups etc. on gitlab.com ? That might be useful to some people? (In which case you probably don't want to implement
instances?? and you shouldn't expect gitlab-rails command to be available?)For the api settings file, (assuming you don't want to make the credentials parameters of each of the individual resources), you can do
confine :exists => '/path/to/api_settings.yaml'in the providers and all types can also haveI'd then probably provide a class that users can use to create this file. eg. the user would do something like...
(With the
gitlab_grouptype, dunno if groups need to know about their parent groups - perhaps so they can autorequire them?)Finally, I've used the gitlab gem before with good results. Maybe the provider should make use of this? (The module could offer to install it and the providers can confine themselves based on whether it's installed yet)
tuxmea commentedon Mar 1, 2022
@alexjfisher sounds like a good idea. But: where can we receive the API token from? Or how to set the token explicitly?
Using gitlab gem also came into my mind. But the same question: how to set or generate the API token?
baurmatt commentedon Mar 1, 2022
The token needs to be provided manually. If you don't want this, you could automate it with a local command as described here. This token would than be saved to e.g.
/etc/gitlab/$user-tokenand loaded by the provider.alexjfisher commentedon Mar 1, 2022
I guess for use with gitlab.com it would have to be manually provided, but if using the module to deploy your own gitlab installation, then being able to automatically generate it would be better.
baurmatt commentedon Mar 1, 2022
Is there an advantage to using these types/providers instead of the official Gitlab Terraform Provider on gitlab.com? While thinking about it... Is it worth developing custom types/provider at all? What would be the benefit?
jay7x commentedon Jul 31, 2025
Haha.. somehow I miss this issue before developing the
gitlab_application_settingsresource type here: #468. So I just put its settings to the/etc/puppetlabs/gitlab_provider.jsonfile 🤷🏻♂️. Feel free to comment the PR (it's more or less done, just miss the SSL support).Biggest issue (not mentioned there) is a token requirement.. I know how to work it around in a VERY WEIRD way, but not sure I'd like to (HINT: look into the rake file in the PR).