Skip to content

Commit 637f622

Browse files
committed
fix null pointer
1 parent 6f164ae commit 637f622

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cmd/nacp/nacp.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func resolveTokenAccessor(transport http.RoundTripper, nomadAddress *url.URL, to
8888
defer resp.Body.Close()
8989

9090
if resp.StatusCode != http.StatusOK {
91-
return nil, fmt.Errorf("failed to resolve token: %s", resp.Status)
91+
return nil, fmt.Errorf("unexpected status code: %s", resp.Status)
9292
}
9393

9494
var aclToken api.ACLToken
@@ -142,12 +142,16 @@ func NewProxyHandler(nomadAddress *url.URL, jobHandler *admissionctrl.JobHandler
142142
tokenInfo, err := resolveTokenAccessor(transport, nomadAddress, token)
143143
if err != nil {
144144
appLogger.Error("Resolving token failed", "error", err)
145-
writeError(w, err)
146145
}
147146
if tokenInfo != nil {
148147
reqCtx.AccessorID = tokenInfo.AccessorID
149148
reqCtx.TokenInfo = tokenInfo
150149
}
150+
}
151+
152+
// Even tho we have resolveToken set to true, the initial connection will be issued without a token for the auth
153+
// so it's better to validate whether it's populated or not
154+
if reqCtx.TokenInfo != nil {
151155
appLogger.Info("Request received", "path", r.URL.Path, "method", r.Method, "clientIP", reqCtx.ClientIP, "accessorID", reqCtx.AccessorID)
152156
} else {
153157
appLogger.Info("Request received", "path", r.URL.Path, "method", r.Method, "clientIP", reqCtx.ClientIP)

0 commit comments

Comments
 (0)