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

feat:add authorization-annotation the ingress resource #985

Merged
merged 47 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
23d09ea
fix ApisixConsumerBasicAuthValue password-yaml field error
AlinsRan Apr 12, 2022
868496f
add consumer-restriction plugin test cases for e2e
AlinsRan Apr 14, 2022
34a5f89
Merge remote-tracking branch 'upstream/master'
AlinsRan Apr 14, 2022
884941d
Merge remote-tracking branch 'upstream/master'
AlinsRan Apr 14, 2022
2d9358e
Merge branch 'master' of github.com:AlinsRan/apisix-ingress-controller
AlinsRan Apr 14, 2022
0496c22
Merge remote-tracking branch 'upstream/master'
AlinsRan Apr 15, 2022
e2c41df
Add 3 plugin test cases for e2e
AlinsRan Apr 15, 2022
7b68daa
Add 3 plugin test cases for e2e
AlinsRan Apr 15, 2022
b19fa8f
delete unwantedweight filed
AlinsRan Apr 15, 2022
9516280
Merge remote-tracking branch 'upstream/master'
AlinsRan Apr 19, 2022
6b95430
add "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
9df451a
update "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
f211226
update "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
037014d
update "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
6b34495
update "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
b4a6544
update "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
41902b2
update "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
d91ffec
update "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
95173ee
update "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
9d26db4
update "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
8a24c35
update "enable authentication and restriction" doc
AlinsRan Apr 19, 2022
556d4d2
update "enable-authentication-and-restriction.md" doc
AlinsRan Apr 19, 2022
1f4bc09
update "enable-authentication-and-restriction.md" doc
AlinsRan Apr 19, 2022
e055049
update an redirect annotation to the ingress resource
AlinsRan Apr 20, 2022
4412286
delete doc
AlinsRan Apr 20, 2022
d5c1156
change redirect field
AlinsRan Apr 21, 2022
e81c754
add redirect-annotation e2e
AlinsRan Apr 21, 2022
af048aa
add redirect-annotations test cases
AlinsRan Apr 22, 2022
640eb65
add auth-annotation
AlinsRan Apr 24, 2022
1915fb7
add auth_annotation e2e
AlinsRan Apr 25, 2022
eac6972
add authorization-annotation and e2e
Apr 26, 2022
b42c972
Merge branch 'apache:master' into auth_annotation
AlinsRan Apr 27, 2022
2961eb0
Revert "add redirect-annotation e2e"
Apr 27, 2022
b8e827d
Update redirect.go
AlinsRan Apr 27, 2022
bfb7012
Update redirect.go
AlinsRan Apr 27, 2022
288068f
Update redirect.go
AlinsRan Apr 27, 2022
8bcb1e6
Update redirect.go
AlinsRan Apr 27, 2022
c66b2bd
resolve pkverify-codegen error
Apr 27, 2022
66eb1d4
Revert "resolve pkverify-codegen error"
Apr 27, 2022
dcc79c5
Update plugin_types.go
AlinsRan Apr 27, 2022
68a01d5
Update plugin_types.go
AlinsRan Apr 27, 2022
418d073
resolve pkverify-codegen error
Apr 27, 2022
a9b6fc2
Update zz_generated.deepcopy.go
AlinsRan Apr 27, 2022
893e142
Update zz_generated.deepcopy.go
AlinsRan Apr 27, 2022
5e8ca78
Update zz_generated.deepcopy.go
AlinsRan Apr 27, 2022
3b24681
Update zz_generated.deepcopy.go
AlinsRan Apr 27, 2022
9133a88
Update pkg/kube/translation/annotations/authorization.go
AlinsRan Apr 28, 2022
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
2 changes: 2 additions & 0 deletions pkg/kube/translation/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
annotations.NewRewriteHandler(),
annotations.NewRedirectHandler(),
annotations.NewForwardAuthHandler(),
annotations.NewBasicAuthHandler(),
annotations.NewKeyAuthHandler(),
}
)

Expand Down
64 changes: 64 additions & 0 deletions pkg/kube/translation/annotations/authorization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You 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 annotations

import (
apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
)

const (
// auth-type: keyAuth | basicAuth
_authType = AnnotationsPrefix + "auth-type"
)

type basicAuth struct{}

// NewkeyBasicHandler creates a handler to convert
// annotations about basicAuth control to APISIX basic-auth plugin.
func NewBasicAuthHandler() Handler {
return &basicAuth{}
}

func (b *basicAuth) PluginName() string {
return "basic-auth"
}

func (b *basicAuth) Handle(e Extractor) (interface{}, error) {
if e.GetStringAnnotation(_authType) != "basicAuth" {
return nil, nil
}
plugin := apisixv1.BasicAuthConfig{}
return &plugin, nil
}

type keyAuth struct{}

// NewkeyAuthHandler creates a handler to convert
// annotations about keyAuth control to APISIX key-auth plugin.
func NewKeyAuthHandler() Handler {
return &keyAuth{}
}

func (k *keyAuth) PluginName() string {
return "key-auth"
}

func (k *keyAuth) Handle(e Extractor) (interface{}, error) {
if e.GetStringAnnotation(_authType) != "keyAuth" {
return nil, nil
}
plugin := apisixv1.KeyAuthConfig{}
return &plugin, nil
}
10 changes: 10 additions & 0 deletions pkg/types/apisix/v1/plugin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,13 @@ type ForwardAuthConfig struct {
UpstreamHeaders []string `json:"upstream_headers,omitempty"`
ClientHeaders []string `json:"client_headers,omitempty"`
}

// BasicAuthConfig is the rule config for basic-auth plugin.
// +k8s:deepcopy-gen=true
type BasicAuthConfig struct {
}

// KeyAuthConfig is the rule config for key-auth plugin.
// +k8s:deepcopy-gen=true
type KeyAuthConfig struct {
}
32 changes: 32 additions & 0 deletions pkg/types/apisix/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions test/e2e/scaffold/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package scaffold

import "fmt"

func (s *Scaffold) ApisixConsumerBasicAuthCreated(name, username, password string) error {
ac := fmt.Sprintf(`
var (
_apisixConsumerBasicAuth = `
apiVersion: apisix.apache.org/v2beta3
kind: ApisixConsumer
metadata:
Expand All @@ -28,6 +28,26 @@ spec:
value:
username: %s
password: %s
`, name, username, password)
`
_apisixConsumerKeyAuth = `
apiVersion: apisix.apache.org/v2beta3
kind: ApisixConsumer
metadata:
name: %s
spec:
authParameter:
keyAuth:
value:
key: %s
`
)

func (s *Scaffold) ApisixConsumerBasicAuthCreated(name, username, password string) error {
ac := fmt.Sprintf(_apisixConsumerBasicAuth, name, username, password)
return s.CreateResourceFromString(ac)
}

func (s *Scaffold) ApisixConsumerKeyAuthCreated(name, key string) error {
ac := fmt.Sprintf(_apisixConsumerKeyAuth, name, key)
return s.CreateResourceFromString(ac)
}
Loading