Repository navigation
Closed
Description
Description:
When configuring Basic Authentication using a Secret containing an .htpasswd file, Envoy Gateway fails to apply the configuration if the file uses CRLF line endings (common in Windows) instead of LF.
The primary issue is a discrepancy between the reported status and the actual state:
SecurityPolicystatus shows asAccepted: Truewith the message "Policy has been accepted."- However, the Envoy Gateway logs reveal that the xDS update was rejected by Envoy with an error:
invalid htpasswd format, invalid SHA hash length. This is likely because the carriage return (\r) is being treated as part of the hash string.
Expected Behavior:
- The xDS translator should be resilient enough to handle both LF and CRLF line endings in
.htpasswdfiles. - OR, the
SecurityPolicyshould be rejected during the validation phase with a clear error message in the Status field, rather than reporting success while the underlying Envoy configuration is failing.
Repro steps:
- Follow the official Basic Authentication task.
- Instead of a standard
.htpasswd, create a Secret using a file with CRLF line endings. You can use the following YAML as a reference (contains a CRLF-encoded htpasswd):
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: basic-auth
data:
# Contains "foo:{SHA}Ys23Ag/5IOWqZCw9QGaVDdHwH00=" with \r\n
.htpasswd: Zm9vOntTSEF9WXMyM0FnLzVJT1dxWkN3OVFHYVZEZEh3SDAwPQ0K- Apply a
SecurityPolicytargeting an HTTPRoute. - Run
kubectl describe securitypolicy/basic-auth-example. It will show:Reason: AcceptedStatus: TrueMessage: Policy has been accepted.
- Check Envoy Gateway logs to see the xDS rejection error.
Environment:
- Gateway Image:
docker.io/envoyproxy/gateway:v1.7.1 - Envoy Image:
docker.io/envoyproxy/envoy:distroless-v1.37.1 - Kubernetes Version: v1.33
Logs:
kubectl describe securitypolicy/basic-auth-example output:
Name: basic-auth-example
Namespace: default
Labels: <none>
Annotations: <none>
API Version: gateway.envoyproxy.io/v1alpha1
Kind: SecurityPolicy
Metadata:
Creation Timestamp: 2026-03-19T02:37:29Z
Generation: 1
Resource Version: 123408604
UID: 6243f724-1783-413c-b275-51a2f63d9063
Spec:
Basic Auth:
Users:
Group:
Kind: Secret
Name: basic-auth
Target Refs:
Group: gateway.networking.k8s.io
Kind: HTTPRoute
Name: backend
Status:
Ancestors:
Ancestor Ref:
Group: gateway.networking.k8s.io
Kind: Gateway
Name: eg
Namespace: envoy-gateway-system
Conditions:
Last Transition Time: 2026-03-19T02:37:29Z
Message: Policy has been accepted.
Observed Generation: 1
Reason: Accepted
Status: True
Type: Accepted
Controller Name: gateway.envoyproxy.io/gatewayclass-controller
Events: <none>
Envoy Gateway logs (deploy/envoy-gateway):
2026-03-19T02:37:29.644Z INFO provider kubernetes/controller.go:607 reconciled gateways successfully{"runner": "provider", "trace_id": "cade7f3b5bbb2184ce6660241c34c0a0", "span_id": "d14e6945331c1157"}
2026-03-19T02:37:29.644Z INFO gateway-api runner/runner.go:190 received an update {"runner": "gateway-api", "trace_id": "cade7f3b5bbb2184ce6660241c34c0a0", "span_id": "6a2676c2a02cabf6", "key": "gateway.envoyproxy.io/gatewayclass-controller"}
2026-03-19T02:37:29.645Z INFO gateway-api gatewayapi/route.go:372 setting 503 direct response in routes due to no ready endpoints {"runner": "gateway-api", "trace_id": "cade7f3b5bbb2184ce6660241c34c0a0", "span_id": "6a2676c2a02cabf6", "routes": ["httproute/default/backend/rule/0/match/0"]}
2026-03-19T02:37:29.646Z INFO infrastructure runner/runner.go:112 received an update {"runner": "infrastructure", "key": "envoy-gateway-system/eg", "delete": false}
2026-03-19T02:37:29.646Z INFO provider kubernetes/status_updater.go:143 received a status update{"runner": "provider", "namespace": "default", "name": "basic-auth-example", "kind": "SecurityPolicy"}
2026-03-19T02:37:29.646Z INFO xds runner/runner.go:274 received an update {"runner": "xds", "trace_id": "cade7f3b5bbb2184ce6660241c34c0a0", "span_id": "d8af2178ad1e0106"}
2026-03-19T02:37:29.653Z ERROR xds cache/snapshotcache.go:388 Envoy rejected the last update with code 13 and message Error adding/updating listener(s) envoy-gateway-system/eg/http: basic auth: invalid htpasswd format, invalid SHA hash length
envoy-gateway-system/eg/www-example-com-https: basic auth: invalid htpasswd format, invalid SHA hash length
2026-03-19T02:37:29.653Z INFO xds v3/simple.go:583 open delta watch ID:169 for type.googleapis.com/envoy.config.listener.v3.Listener Resources:map[] from nodeID: "envoy-envoy-gateway-system-eg-c3508b54-5577b8478kdhc4", version "cade7f3b5bbb2184ce6660241c34c0a0"
2026-03-19T02:37:29.654Z ERROR xds cache/snapshotcache.go:388 Envoy rejected the last update with code 13 and message basic auth: invalid htpasswd format, invalid SHA hash length
Activity
stekole commentedon Mar 19, 2026
I was able to replicate this locally and confirmed.
SecurityPolicy says Accepted: True / "Policy has been accepted."
and Envoy logs show: invalid htpasswd format, invalid SHA hash length
Looks like something in https://github.com/envoyproxy/gateway/blob/main/internal/gatewayapi/securitypolicy.go#L2030 and may require normalize
validateHtpasswdFormatand return cleaned bytesI could take a look at fixing.
zirain commentedon Mar 19, 2026
cc @zhaohuabing
zhaohuabing commentedon Mar 19, 2026
@stekole It seems that you already have a fix, feel free to open a pr.
stekole commentedon Mar 19, 2026
/assign
fix: normalize CRLF line endings in htpasswd basic auth secrets (envo…
fix: normalize CRLF line endings in htpasswd basic auth secrets (envo…
[release/v1.6] cherry-pick for v1.6.6 (#8761)