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

Returning authenticated cookie when using TO Client Cert Auth #7984

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Updated Go version to 1.22.0

### Fixed
- [#7984](https://github.com/apache/trafficcontrol/pull/7984) *Traffic Ops* Fixed TO Client cert authentication with respect to returning response cookie.
- [#7957](https://github.com/apache/trafficcontrol/pull/7957) *Traffic Ops* Fix the incorrect display of delivery services assigned to ORG servers.
- [#7917](https://github.com/apache/trafficcontrol/pull/7917) *Traffic Ops* Removed `Alerts` field from struct `ProfileExportResponse`.
- [#7918](https://github.com/apache/trafficcontrol/pull/7918) *Traffic Portal* Fixed topology link under DS-Servers tables page
Expand Down
5 changes: 5 additions & 0 deletions traffic_ops/testing/api/v5/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,10 @@ func TestLoginWithCert(t *testing.T) {
if session == nil {
t.Fatalf("expected a valid session, but got nothing")
}

_, _, err = session.GetAbout(client.RequestOptions{})
if err != nil {
t.Fatalf("expected no error while using the client cert session to hit an authenticated endpoint, but got %v", err)
}
}
}
9 changes: 9 additions & 0 deletions traffic_ops/toclientlib/toclientlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ func LoginWithCert(
if err != nil {
return nil, nil, err
}

jar, err := cookiejar.New(&cookiejar.Options{
PublicSuffixList: publicsuffix.List,
})
if err != nil {
return nil, nil, errors.New("creating cookie jar: " + err.Error())
}

to := NewClient("", "", toURL, userAgent, &http.Client{
Timeout: requestTimeout,
Transport: &http.Transport{
Expand All @@ -357,6 +365,7 @@ func LoginWithCert(
InsecureSkipVerify: insecure,
},
},
Jar: jar,
}, apiVersions)

reqInf, err := to.login()
Expand Down
4 changes: 2 additions & 2 deletions traffic_ops/traffic_ops_golang/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Subject: {{.InstanceName}} Password Reset Request` + "\r\n\r" + `
</html>
`))

func clientCertAuthentication(w http.ResponseWriter, r *http.Request, db *sqlx.DB, cfg config.Config, dbCtx context.Context, cancelTx context.CancelFunc, form auth.PasswordForm, authenticated bool) bool {
func clientCertAuthentication(w http.ResponseWriter, r *http.Request, db *sqlx.DB, cfg config.Config, dbCtx context.Context, cancelTx context.CancelFunc, form *auth.PasswordForm, authenticated bool) bool {
// No certs provided by the client. Skip to form authentication
if r.TLS == nil || len(r.TLS.PeerCertificates) == 0 {
return false
Expand Down Expand Up @@ -171,7 +171,7 @@ func LoginHandler(db *sqlx.DB, cfg config.Config) http.HandlerFunc {
// Attempt to perform client certificate authentication. If fails, goto standard form auth. If the
// certificate was verified, has a UID, and the UID matches an existing user we consider this to
// be a successful login.
authenticated = clientCertAuthentication(w, r, db, cfg, dbCtx, cancelTx, form, authenticated)
authenticated = clientCertAuthentication(w, r, db, cfg, dbCtx, cancelTx, &form, authenticated)

// Failed certificate-based auth, perform standard form auth
if !authenticated {
Expand Down
Loading