-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add an option to create a default project for a new user #16731
Comments
Harbor doesn't currently support that, but we created a stored procedure at Container-Registry for c8n.io. would love to see this working out of the box but in the meantime --
-- Create for each new user a new project same as username with 1G of quota.
-- Customization for C8N, each new user should have his own project with a quota.
CREATE OR REPLACE FUNCTION create_project_for_new_user()
RETURNS TRIGGER AS
$$
DECLARE
new_project_id int;
BEGIN
IF NEW.user_id IS NULL THEN
RAISE EXCEPTION 'NEW.user_id has to be set';
END IF;
INSERT INTO public.project (owner_id, name)
VALUES (1, lower(regexp_replace(NEW.username, '\W+', '', 'g')))
RETURNING project.project_id INTO new_project_id;
INSERT INTO public.project_member (project_id, entity_id, entity_type, role)
VALUES (new_project_id, NEW.user_id, 'u', 4);
INSERT INTO public.quota (reference, reference_id, hard)
VALUES ('project', new_project_id, '{"storage": 1073741824}');
INSERT INTO public.quota_usage (reference, reference_id, used)
VALUES ('project', new_project_id, '{"storage": 0}' );
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DO
$$
BEGIN
IF NOT EXISTS
(SELECT *
FROM information_schema.triggers
WHERE event_object_table = 'harbor_user'
AND trigger_name = 'new_harbor_user_create_project_trigger')
THEN
CREATE TRIGGER new_harbor_user_create_project_trigger
AFTER INSERT
ON harbor_user
FOR EACH ROW
EXECUTE PROCEDURE create_project_for_new_user();
END IF;
END;
$$ |
Thank you for the solution @Vad1mo ! I'm not familiar with PostgreSQL much, can I just paste this into the interactive console that's started with |
yes |
This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days. |
Is your feature request related to a problem? Please describe.
At our company we would like to provide users with a place where to store their docker images. We want each user to have their own project (mainly for storage quotas purposes), however it is not feasible to create a new project for every user that wants to use our harbor instance.
Describe the solution you'd like
We would like to have an option to create a new project when a new user is created. Our instance is connected to an OIDC, so we would like for the user to log in through OIDC and have their project ready as soon as possible after they log in for the first time.
If this behavior isn't simple to implement we would also be okay with addition of an option that causes a webhook call with user information in it. We would then use this call to create a new project through Harbor API.
I hope at least one of these approaches is feasible to implement into the project.
The text was updated successfully, but these errors were encountered: