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

examples: add example to illustrate the use of file watcher interceptor #7226

Merged
merged 7 commits into from
May 28, 2024

Conversation

Kailun2047
Copy link
Contributor

@Kailun2047 Kailun2047 commented May 10, 2024

Summary of changes:

  • Add example to illustrate the use of file watcher authz interceptor

Fixes #5900

RELEASE NOTES: none

@Kailun2047 Kailun2047 marked this pull request as ready for review May 10, 2024 14:42
@Kailun2047 Kailun2047 changed the title authz: add example to illustrate the use of file watcher interceptor examples: add example to illustrate the use of file watcher interceptor May 10, 2024
@easwars easwars added the Type: Documentation Documentation or examples label May 13, 2024
@easwars easwars self-assigned this May 13, 2024
@easwars easwars added this to the 1.65 Release milestone May 13, 2024
Copy link
Contributor

@easwars easwars left a comment

Choose a reason for hiding this comment

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

Looks very good. Just some minor nits. Thanks for doing this.

examples/features/authz/README.md Show resolved Hide resolved
examples/features/authz/README.md Outdated Show resolved Hide resolved
@Kailun2047
Copy link
Contributor Author

@easwars Comments addressed. Please take another look when you get time. Thanks.

@dfawley dfawley assigned gtcooke94 and unassigned Kailun2047 May 14, 2024
@dfawley
Copy link
Member

dfawley commented May 21, 2024

@gtcooke94 Can you take a second pass on this review? Thanks!

Copy link
Contributor

@gtcooke94 gtcooke94 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! A few comments

```

The client will first hit `codes.PermissionDenied` error when invoking
`UnaryEcho` although a legit username (`super-user`) is associated. This is
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: UnaryEcho although a legitimate username (super-user) is associated with the RPC.

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.

)

var (
port = flag.Int("port", 50051, "the port to serve on")
port = flag.Int("port", 50051, "the port to serve on")
authzOpt = flag.String("authz-option", authzOptStatic, "the authz option (static or file watcher)")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: file watcher -> filewatcher

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.

switch *authzOpt {
case authzOptStatic:
// Create an authorization interceptor using a static policy.
staticInt, err := authz.NewStatic(authzPolicy)
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer the full name Interceptor rather than shortening to Int, please change throughout

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.

}
unaryAuthzInt, streamAuthzInt = fileWatcherInt.UnaryInterceptor, fileWatcherInt.StreamInterceptor
default:
log.Fatalf("Invalid authz option: %s", *authzOpt)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this example server is specifically for authz, let's put this check earlier (after parsing flags), then error log and exit the process if an invalid authz option is specified.

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.

@gtcooke94 gtcooke94 assigned Kailun2047 and unassigned gtcooke94 May 22, 2024
@Kailun2047
Copy link
Contributor Author

@gtcooke94 Comments addressed. Please take another look when you get time. Thanks!

@aranjans aranjans assigned gtcooke94 and unassigned Kailun2047 May 27, 2024
Copy link
Contributor

@gtcooke94 gtcooke94 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the PR!

@gtcooke94 gtcooke94 merged commit 6e59dd1 into grpc:master May 28, 2024
12 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Documentation Documentation or examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an example to illustrate the use of authz package
4 participants