Skip to content

Expand list of accepted ENV vars for openstack.AuthOptionsFromEnv - #3657

Open
danchild wants to merge 2 commits into
gophercloud:mainfrom
danchild:patch-issue-3440
Open

Expand list of accepted ENV vars for openstack.AuthOptionsFromEnv#3657
danchild wants to merge 2 commits into
gophercloud:mainfrom
danchild:patch-issue-3440

Conversation

@danchild

@danchild danchild commented Mar 23, 2026

Copy link
Copy Markdown

Fixes #3440 #3240

According to the OpenStack API documentation, OS_USER_DOMAIN_ID, OS_USER_DOMAIN_NAME, OS_PROJECT_DOMAIN_ID, AND OS_PROJECT_DOMAIN_NAME are all valid inputs for identity v3. The current
implementation of openstack.AuthOptionsFromEnv does not accept these environment variables as inputs.

This fix keeps the gophercloud.AuthOptions struct intact, keeping the semantics of the name domainID and domainName unchanged so we do not need refactor code that consumes the the struct. Instead a new implementation
of openstack.AuthOptionsFromEnv would check for the presence of the OS_USER_DOMAIN_X and
OS_PROJECT_DOMAIN_X environment variables and set domainID and domainName accordingly.

The difficult part is to resolve ambiguity between the env vars passed in and provide either warnings or errors
to the users depending on different combinations. Given that the approach to not changing gophercloud.AuthOptions
is the best path forward, dealing with this ambiguity needs to be iterated on, and I certainly need some help determining what users expect and what makes sense base on OpenStack identity v3 conventions.

Links to the line numbers/files in the OpenStack source code that support the
code in this PR:

API Reference: https://docs.openstack.org/python-openstackclient/2025.2/cli/authentication.html

@github-actions github-actions Bot added edit:openstack This PR updates common OpenStack code edit:gophercloud This PR updates common Gophercloud code semver:minor Backwards-compatible change backport-v2 This PR will be backported to v2 labels Mar 23, 2026
@winiciusallan

Copy link
Copy Markdown
Contributor

Hi @danchild, thanks for the PR.

Didn't take a look at the changes, but for reference, I would take a look at this issue, there may be useful discussions to take forward.

@coveralls

coveralls commented Mar 27, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 63.689% (+0.2%) from 63.519% — danchild:patch-issue-3440 into gophercloud:main

@danchild

danchild commented Apr 8, 2026

Copy link
Copy Markdown
Author

Hi @mandre regarding the failed tests, I just pushed a new commit that allows for OS_DOMAIN_X to be set alongside OS_USER_DOMAIN_X and OS_PROJECT_DOMAIN_X provided that they are the same values. I also added a check to test if there is ambiguity between OS_TENANT_X and OS_PROJECT_X which hadn't been done in previous versions.

@winiciusallan winiciusallan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @danchild, I took a look at your changes, but I will need to do another round of review. This PR is very important to improve how Gophercloud is handling authentication.

I would say that my impression is that we now have a long function which is handling a lot of validations--most of them are doing the same kind of verification--, and this may be hard to maintain in the future. So, I believe we could extract these things to separate helper functions and use them accordingly.

Besides, IMO it would be good to document how the validation process is. For example, 1) verify the scope, 2) override domain variables for backward compatibility, ...

Another pair of eyes here would be good

Comment thread openstack/auth_env.go Outdated
Comment thread openstack/auth_env.go Outdated
Comment thread openstack/auth_env.go Outdated
@danchild

danchild commented May 4, 2026

Copy link
Copy Markdown
Author

Hi @winiciusallan sorry for the late reply here, and thank you for your feedback. I agree with you that creating helper functions would make the intent clearer and documenting the process as well. I will work on those and message you with an update.

@winiciusallan winiciusallan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I've added a few comments, nothing that big. If you want to wait for another review to submit a new commit, I'd say it's up to you.

I would like to see how tests will behave.

Comment thread openstack/testing/auth_env_test.go Outdated
Comment thread openstack/testing/auth_env_test.go Outdated
Comment thread openstack/testing/auth_env_test.go Outdated
Comment thread openstack/testing/auth_env_test.go Outdated

@mandre mandre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not sure about this PR. This adds a lot of complexity in a critical, and already complex part of the code.

The root problem seems to be that gophercloud.AuthOptions has a single DomainID/DomainName field rather than separate user-domain and project-domain fields. Until we fix this properly and add more fields to gophercloud.AuthOptions, I think we can't make it work for all cases.

Perhaps, instead of trying to make it work for all cases with the current gophercloud.AuthOptions limitation, we should instead focus on making the failure case for downloaded default openrc from horizon more user friendly (if that's really the issue)?

Comment thread openstack/auth_env.go Outdated
@danchild

danchild commented Jun 1, 2026

Copy link
Copy Markdown
Author

Hi @mandre thank you for the feedback and I apologize for the delay. Give me a few weeks and I'll push changes with the default openrc as the primary lens for acceptance

@danchild
danchild force-pushed the patch-issue-3440 branch 2 times, most recently from c3ca82e to b845a23 Compare June 11, 2026 16:42
@github-actions github-actions Bot added the edit:identity This PR updates identity code label Jun 11, 2026
@danchild

Copy link
Copy Markdown
Author

Hi @mandre - I took a stab at applying the fix through the lens of accepting the default openrc file from horizon. It's become clear that ToTokenV3ScopeMap was too strict in its original design. For example, it doesn't allow project name and project id to be set at the same time, and yet they are both provided on the default openrc. The patch here does the following:

1) Removes the restrictiveness, relying on keystone to handle its own errors
2) Silently, prioritize OS_USER_* and OS_PROJECT_* over the legacy OS_DOMAIN_*

This works and is perhaps overly permissive, but it jives with the project's goals of prioritizing freedom over restrictions. Can you please provide your feedback on the patch?

@winiciusallan - if you have any thoughts too please chime in.

@danchild
danchild requested a review from mandre June 11, 2026 16:56
danchild added 2 commits June 11, 2026 15:18
AuthOptionsFromEnv now reads OS_USER_DOMAIN_ID, OS_USER_DOMAIN_NAME,
OS_PROJECT_DOMAIN_ID, and OS_PROJECT_DOMAIN_NAME. User-domain variables
take precedence over the legacy OS_DOMAIN_* variables, and project-domain
variables are used to scope the authentication request.

Overly strict scope validation that rejected valid OpenStack
configurations (e.g. ProjectID with DomainID, or ProjectName without
an explicit domain) has been removed along with the corresponding
error types ErrScopeDomainIDOrDomainName, ErrScopeProjectIDOrProjectName,
and ErrScopeProjectIDAlone.

For gophercloud#3440
Cover admin and demo openrc configurations, OS_USER_DOMAIN_*
precedence over OS_DOMAIN_*, OS_PROJECT_DOMAIN_* handling, and
legacy fallback behavior.
@github-actions github-actions Bot added semver:major Breaking change and removed semver:minor Backwards-compatible change backport-v2 This PR will be backported to v2 labels Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

edit:gophercloud This PR updates common Gophercloud code edit:identity This PR updates identity code edit:openstack This PR updates common OpenStack code semver:major Breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V3 Auth not properly implemented

4 participants