-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support basic authorization (#540)
## What type of PR is this? /kind feature ## What this PR does / why we need it: This PR provides the login functionality, which is essential in a production environment. ## Which issue(s) this PR fixes: Fixes #497 --------- Co-authored-by: elliotxx <951376975@qq.com> Co-authored-by: hai-tian <tianhai_th@163.com> Co-authored-by: hai-tian <wb-th358723@antgroup.com>
- Loading branch information
1 parent
cd63e91
commit 66ab414
Showing
41 changed files
with
1,548 additions
and
676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: karpor-admin | ||
rules: | ||
- nonResourceURLs: | ||
- /rest-api/v1/resource-group-rule | ||
- /rest-api/v1/resource-group-rule/* | ||
- /rest-api/v1/cluster | ||
- /rest-api/v1/cluster/* | ||
verbs: | ||
- '*' | ||
- nonResourceURLs: | ||
- / | ||
- /rest-api/* | ||
- /endpoints | ||
- /public/* | ||
- /docs/* | ||
- /server-configs | ||
- /search | ||
- /search/* | ||
- /insight | ||
- /insight/* | ||
- /insightDetail | ||
- /insightDetail/* | ||
- /cluster | ||
- /cluster/* | ||
- /login | ||
- /rest-api/v1/authn | ||
- /livez | ||
- /readyz | ||
verbs: | ||
- get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: karpor-guest | ||
rules: | ||
- nonResourceURLs: | ||
- /rest-api/v1/resource-group-rule | ||
- /rest-api/v1/resource-group-rule/* | ||
- /rest-api/v1/cluster | ||
- /rest-api/v1/cluster/* | ||
- /rest-api/v1/authn | ||
- / | ||
- /rest-api/* | ||
- /endpoints | ||
- /public/* | ||
- /docs/* | ||
- /server-configs | ||
- /search | ||
- /search/* | ||
- /insight | ||
- /insight/* | ||
- /insightDetail | ||
- /insightDetail/* | ||
- /cluster | ||
- /cluster/* | ||
- /login | ||
- /livez | ||
- /readyz | ||
verbs: | ||
- get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright The Karpor Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package authn | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/KusionStack/karpor/pkg/core/handler" | ||
) | ||
|
||
// Get returns an HTTP handler that determine whether the user's token can pass authentication. | ||
// | ||
// @Summary Get returns an authn result of user's token. | ||
// @Description This endpoint returns an authn result. | ||
// @Tags authn | ||
// @Produce json | ||
// @Success 200 {string} string "OK" | ||
// @Failure 400 {string} string "Bad Request" | ||
// @Failure 401 {string} string "Unauthorized" | ||
// @Failure 404 {string} string "Not Found" | ||
// @Failure 405 {string} string "Method Not Allowed" | ||
// @Failure 429 {string} string "Too Many Requests" | ||
// @Failure 500 {string} string "Internal Server Error" | ||
// @Router /authn [get] | ||
func Get() http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
// No action is taken as the API server will handle authentication. | ||
handler.HandleResult(w, r, r.Context(), nil, "") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.