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

support grpc auth for grpc server. #168

Merged
merged 2 commits into from
Sep 5, 2024

Conversation

morvencao
Copy link
Contributor

@morvencao morvencao commented Aug 2, 2024

Add authentication and authorization for gRPC server, using kube authorizer:

  • mtls based authorization
  • token based authorization

how to configure authentication and authorization doc: https://github.com/morvencao/openshift-online-maestro/blob/br_grpc_auth/docs/grpc.md#authentication-and-authorization

ref:

@morvencao morvencao changed the title [WIP] support grpc auth. support grpc auth for grpc server. Aug 5, 2024
@morvencao morvencao force-pushed the br_grpc_auth branch 5 times, most recently from 3a4f400 to 420b812 Compare August 6, 2024 02:05
@morvencao
Copy link
Contributor Author

/assign @qiujian16 @clyang82 @skeeey

@morvencao morvencao force-pushed the br_grpc_auth branch 15 times, most recently from 7d3b22e to 37489b4 Compare August 12, 2024 13:32
@clyang82
Copy link
Contributor

/ok-to-test

@morvencao morvencao force-pushed the br_grpc_auth branch 7 times, most recently from 4ade853 to 93df2b2 Compare August 29, 2024 11:21
Signed-off-by: morvencao <lcao@redhat.com>
@morvencao
Copy link
Contributor Author

morvencao commented Aug 29, 2024

rebased the code, added document for how to configure grpc server authN and authZ.

e.Clients.GRPCAuthorizer = grpcauthorizer.NewMockGRPCAuthorizer()
} else {
kubeConfig, err := clientcmd.BuildConfigFromFlags("", e.Config.GRPCServer.GRPCAuthrizerConfig)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/GRPCAuthrizerConfig/GRPCAuthorizerConfig

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -126,7 +126,7 @@ func NewAPIServer(eventBroadcaster *event.EventBroadcaster) Server {

// TODO: support authn and authz for gRPC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment since we support it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this.


// newAuthUnaryInterceptor creates a new unary interceptor that looks up the client certificate from the incoming RPC context,
// retrieves the user and groups from it and creates a new context with the user and groups before invoking the provided handler.
// otherwise, it falls back retrieving the user and groups from the access token.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment is to look up the client cert and then token. but the implement is to look up token and then client cert.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use --grpc-authn-type to decide that where to get the user and group.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original idea is even if we specify the --grpc-authn-type=token, we may still can retrieve user/group from client certificate if the token is not provided.
Anyway, I will use --grpc-authn-type to decide that how to get the user and group.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated this use --grpc-authn-type to decide that how to get the user and group.

fs.StringVar(&s.TLSCertFile, "grpc-tls-cert-file", "", "The path to the tls.crt file")
fs.StringVar(&s.TLSKeyFile, "grpc-tls-key-file", "", "The path to the tls.key file")
fs.BoolVar(&s.EnableTLS, "enable-grpc-tls", false, "Enable TLS for gRPC server")
fs.StringVar(&s.GRPCAuthNType, "grpc-authn-type", "mock", "Specify the gRPC authentication type (e.g., mock, mtls or token)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe disable grpc authn instead of using mock. using mock seems it is not ready for use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to simplify the code and make it easy for users to learn, so I'd prefer not to add another parameter for this.

nonResourceUrl = fmt.Sprintf("/sources/%s", resource)
case "cluster":
nonResourceUrl = fmt.Sprintf("/clusters/%s", resource)
default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source and cluster are not the same level concept. what do you mean cluster?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if configure both, what is the behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we don't need cluster for now, because currently authZ is for source side, not for agent side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed cluster for now.

Signed-off-by: morvencao <lcao@redhat.com>
Copy link
Contributor

@clyang82 clyang82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@clyang82 clyang82 merged commit 908246a into openshift-online:main Sep 5, 2024
7 checks passed
@morvencao morvencao deleted the br_grpc_auth branch September 5, 2024 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants