Skip to content
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

Custom authorization header for http backend is dropped #1656

Closed
boetro opened this issue May 18, 2024 · 2 comments · Fixed by #1657
Closed

Custom authorization header for http backend is dropped #1656

boetro opened this issue May 18, 2024 · 2 comments · Fixed by #1657
Labels
bug Something isn't working pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion.

Comments

@boetro
Copy link
Contributor

boetro commented May 18, 2024

OpenTofu Version

OpenTofu v1.7.1
on darwin_arm64

OpenTofu Configuration Files

terraform {
  backend "http" {
    address = "http://localhost:8000"
    headers = {
        "authorization" = "Bearer access-token"
        "Cache-Control" = "no-cache"
    }
  }
}

Debug Output

Initializing the backend...
2024-05-18T13:34:23.144-0500 [TRACE] Meta.Backend: built configuration for "http" backend with hash value 3930140512
2024-05-18T13:34:23.144-0500 [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2024-05-18T13:34:23.144-0500 [DEBUG] New state was assigned lineage "8ef6b437-6995-5c21-7e6b-c8bed03ddc5c"
2024-05-18T13:34:23.144-0500 [TRACE] Meta.Backend: moving from default local state only to "http" backend
2024-05-18T13:34:23.144-0500 [DEBUG] checking for provisioner in "."
2024-05-18T13:34:23.145-0500 [DEBUG] checking for provisioner in "/opt/homebrew/bin"
2024-05-18T13:34:23.145-0500 [TRACE] backend/local: state manager for workspace "default" will:

  • read initial snapshot from terraform.tfstate
  • write new snapshots to terraform.tfstate
  • create any backup at terraform.tfstate.backup
    2024-05-18T13:34:23.145-0500 [TRACE] statemgr.Filesystem: reading initial snapshot from terraform.tfstate
    2024-05-18T13:34:23.145-0500 [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
    2024-05-18T13:34:23.145-0500 [TRACE] statemgr.Filesystem: read nil snapshot
    2024-05-18T13:34:23.145-0500 [TRACE] Meta.Backend: ignoring local "default" workspace because its state is empty
    2024-05-18T13:34:23.148-0500 [DEBUG] New state was assigned lineage "bb51cbaf-bd80-b95a-b781-5494d3af9f53"
    2024-05-18T13:34:23.148-0500 [TRACE] Preserving existing state lineage "bb51cbaf-bd80-b95a-b781-5494d3af9f53"

Successfully configured the backend "http"! OpenTofu will automatically
use this backend unless the backend configuration changes.
2024-05-18T13:34:23.152-0500 [TRACE] Meta.Backend: instantiated backend of type *http.Backend
2024-05-18T13:34:23.152-0500 [DEBUG] checking for provisioner in "."
2024-05-18T13:34:23.152-0500 [DEBUG] checking for provisioner in "/opt/homebrew/bin"
2024-05-18T13:34:23.153-0500 [TRACE] Meta.Backend: backend *http.Backend does not support operations, so wrapping it in a local backend
2024-05-18T13:34:23.153-0500 [DEBUG] GET http://localhost:8000/
Error refreshing state: HTTP remote state endpoint invalid auth

Expected Behavior

On my server I printed the headers attached to the HTTP request and got the following:

{'host': 'localhost:8000', 'user-agent': 'Go-http-client/1.1', 'cache-control': 'no-cache', 'accept-encoding': 'gzip'}

Actual Behavior

I expect the authorization header to be contained in the list of headers. It looks like any other header works besides the authorization one

Steps to Reproduce

  1. Set up a simple http endpoint that prints headers for a request
  2. tofu init

Additional Context

I believe this is because of this line here: https://github.com/bunniseng/opentofu/blob/main/internal/backend/remote-state/http/backend.go#L261

which doesn't fall through to the default case

References

No response

@boetro boetro added bug Something isn't working pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion. labels May 18, 2024
@boetro
Copy link
Contributor Author

boetro commented May 18, 2024

I'm happy to take a stab at fixing this should be pretty straight forward I believe

@boetro
Copy link
Contributor Author

boetro commented May 18, 2024

Fix should be here: #1657

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending-decision This issue has not been accepted for implementation nor rejected. It's still open to discussion.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant