Skip to content

Oss 133 new detector vault approle auth for hashicorp #4362

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

Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions pkg/detectors/hashicorpvaultauth/hashicorpvaultauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,30 +125,32 @@ func verifyMatch(ctx context.Context, client *http.Client, roleId, secretId, vau
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Vault-Namespace", "admin")

res, err := client.Do(req)
resp, err := client.Do(req)
if err != nil {
return false, err
}

defer func() {
_, _ = io.Copy(io.Discard, res.Body)
_ = res.Body.Close()
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()
}()

switch res.StatusCode {
switch resp.StatusCode {
case http.StatusOK:
return true, nil
case http.StatusBadRequest:
if err := json.NewDecoder(res.Body).Decode(&errorResponse); err == nil {
if errorResponse.Errors[0] == "invalid role or secret ID" {
return false, nil
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return false, err
}

if strings.Contains(string(body), "invalid role or secret ID") {
return false, nil
} else {
return false, fmt.Errorf("bad request: %v", errorResponse.Errors)
}
default:
return false, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)
return false, fmt.Errorf("unexpected HTTP response status %d", resp.StatusCode)
}
}

Expand Down