-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
We need CGO to not be disabled in order for netcgo to work properly. #13878
base: main
Are you sure you want to change the base?
Conversation
@@ -208,7 +208,6 @@ jobs: | |||
GOOS: ${{ matrix.goos }} | |||
GOARCH: ${{ matrix.goarch }} | |||
GO_TAGS: "${{ env.GO_TAGS }} netcgo" | |||
CGO_ENABLED: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Injecting myself where I have no business, but if we need CGO for Darwin builds, should we not be explicit about it? Sorry if I completely missed the context...
CGO_ENABLED: 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that CGO_ENABLED is a tristate, and unset is different from 0 or 1. I believe unset CGO_ENABLED is the minimal change necessary to make this work. But it's entirely possible that I'm missing something here and that the situation is simpler (or more complex) than I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When building with CGO_ENABLED
missing from the environment, adding netcgo
to GO_TAGS
does not enable proper DNS resolution on macOS.
Test:
% GO_TAGS=netcgo make dev
% vault login -method=oidc
Error authenticating: Put "https://vault.example.internal/v1/auth/oidc/oidc/auth_url": dial tcp: lookup vault.example.internal on 172.16.108.111:53: no such host
example.internal
is configured in macOS to be sent to a DNS server at 10.10.40.41
but is still using my non VPN dns server.
Next test:
% CGO_ENABLED=1 GO_TAGS=netcgo make dev
==> Checking that build is using go version >= 1.17.5...
==> Using go version 1.17.6...
==> Removing old directory...
==> Building...
Number of parallel builds: 11
--> darwin/amd64: github.com/hashicorp/vault
==> Results:
total 372120
-rwxr-xr-x 1 c5309377 staff 182M Feb 2 17:04 vault
% vault login -method=oidc
Complete the login via your OIDC provider. Launching browser to:
https://sso.example.internal/auth/realms/test/protocol/openid-connect/auth?client_id=vault&nonce=fdd8a2f553cd61bf485507d07767d5556dc53ac1&redirect_uri=http%3A%2F%2Flocalhost%3A8250%2Foidc%2Fcallback&response_type=code&scope=openid&state=d783d93ffd93dd3b385350f55610ad20a2e7b458
Waiting for OIDC authentication to complete...
Success! You are now authenticated. The token information displayed below
is already stored in the token helper. You do NOT need to run "vault login"
again. Future Vault requests will automatically use this token.
Key Value
--- -----
token s.POgDQgfP85Hld0GWC343Ws18
token_accessor ACeIQhKo2WLiqESysljCeFdS
token_duration 24h
token_renewable true
token_policies ["default"]
identity_policies []
policies ["default"]
token_meta_role default
% vault --version
Vault v1.10.0-dev ('2999fb8865772a40e389438a5fc21e0e98876dcd') (cgo)
@archoversight I haven't had time to work on this lately, but I will come back to it soon. In the meantime, a colleague pointed out that your test with Really I need to make time to figure out how to test this locally. If you have any tips that don't require setting up openvpn I'm interested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ncabatoff My understanding of CGO_ENABLED
matches yours and we want to leave it unset for MacOS builds.
In the context of this particular issue, what was observed(1) was that setting CGO_ENABLED=1
on MacOS forces go
into an external linker mode (2), and will try to use ld64
from the Apple Developer Tools. This became an issue when targeting ARM. Since we don't have MacOS ARM build hosts, we still have to cross compile those binaries and getting go to use the correct version of the developer tools was not easy (I forget the details now 😞), but we don't actually need the system linker. The go linker is perfectly capable of linking darwin/arm
from darwin/amd64
. We only care that it is able to load system libraries so that it can use native dns resolution at runtime, which is the behavior with CGO_ENABLED=1
or unset.
- I was unable to find a definitive statement on this observed behavior
- I was unable to find the right flag/combination of flags to force to use an internal linker when
CGO_ENABLED=1
. Passing the linker-linkmode internal
was ignored and it would still try to use the system linker.
As far as -tags=netcgo
, that is the default behavior on MacOS when CGO_ENABLED=1
or is unset. We're choosing to make it explicit here.
@ncabatoff Alright, so based upon your statement I tried compiling with no
Attempting to use it against an instance that is across split DNS:
Running
Recompiling with
No matter what flags I set, or how I set them, I have to enable That is whether I use
Broken:
|
Do note that terraform fixed this by building on macOS, and since the toolchain contains the headers/information for both x86_64 and arm64 they were able to build both: Could the same technique not be used here for vault? |
Is there anyway to get this work prioritized/completed so that binaries on macOS are able to resolve using the system resolver and thus can use split DNS? |
I wonder if, as part of finalizing this journey, it might make sense to revisit whether to continue setting the According to the big comment in https://go.googlesource.com/go/+/go1.20/src/net/net.go, Go has good reasons to prefer its native DNS implementation when it can, and makes efforts to automatically transition to the cgo resolver if needed... and in particular, it already automatically defaults to cgo DNS resolution when running on darwin anyway!
(from Go |
Fixes #12012.