-
-
Notifications
You must be signed in to change notification settings - Fork 273
refactor: use modular approach for k8s extractors #1154
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
Open
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
419da20
feat(k8s): Support new Gateway api
contre95 2769725
feat(k8s): Support for GRPCRoute
contre95 3a216e9
Merge branch 'main' into feat/k8s_gateways
contre95 e1b1e72
fix(acl): only let a label provider define ACLs for domains it routes
contre95 5a685c4
Merge branch 'main' into feat/k8s_gateways
steveiliop56 b43cf76
refactor: use typed objects for kubernetes
steveiliop56 45e165f
tests: add tests for kubernetes service and extractors
steveiliop56 34456b9
chore: add missing acls service modification for domain normalization
steveiliop56 90e898a
Merge branch 'main' into feat/k8s_gateways
steveiliop56 996316b
chore: remove gateway extractors
steveiliop56 11a60fe
refactor: remove domain arg from label provider
steveiliop56 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,68 @@ | ||
| package service | ||
|
|
||
| import ( | ||
| "slices" | ||
|
|
||
| "github.com/tinyauthapp/tinyauth/internal/utils/logger" | ||
| networking "k8s.io/api/networking/v1" | ||
| ) | ||
|
|
||
| type KubernetesIngressExtractor struct { | ||
| log *logger.Logger | ||
| } | ||
|
|
||
| type KubernetesIngressExtractorInput struct { | ||
| Log *logger.Logger | ||
| } | ||
|
|
||
| func NewKubernetesIngressExtractor(i KubernetesIngressExtractorInput) *KubernetesIngressExtractor { | ||
| return &KubernetesIngressExtractor{ | ||
| log: i.Log, | ||
| } | ||
| } | ||
|
|
||
| func (k *KubernetesIngressExtractor) getPaths(rule networking.IngressRule) []string { | ||
| var paths []string | ||
|
|
||
| if rule.HTTP == nil { | ||
| return paths | ||
| } | ||
|
|
||
| for _, path := range rule.HTTP.Paths { | ||
| paths = append(paths, path.Path) | ||
| } | ||
|
|
||
| return paths | ||
| } | ||
|
|
||
| func (k *KubernetesIngressExtractor) getHosts(rules []networking.IngressRule) []string { | ||
| var hosts []string | ||
|
|
||
| for _, rule := range rules { | ||
| hosts = append(hosts, rule.Host) | ||
| paths := k.getPaths(rule) | ||
|
|
||
| if len(paths) == 0 { | ||
| continue | ||
| } | ||
|
|
||
| if !slices.Contains(paths, "/") { | ||
| k.log.App.Warn().Strs("hosts", hosts).Strs("paths", paths).Msg("Ingress rule does not contain a catch-all path, another ingress may be able to bypass auth checks if it routes the same host with a different path. Consider adding a catch-all path to this rule to ensure auth checks are applied to all paths for this host.") | ||
| } | ||
| } | ||
|
|
||
| return hosts | ||
| } | ||
|
|
||
| func (k *KubernetesIngressExtractor) Extract(ingress *networking.Ingress) *ExtractionResult { | ||
| annotations := ingress.GetAnnotations() | ||
| hosts := k.getHosts(ingress.Spec.Rules) | ||
|
|
||
| return &ExtractionResult{ | ||
| typ: ResourceTypeIngress, | ||
| name: ingress.GetName(), | ||
| namespace: ingress.GetNamespace(), | ||
| hosts: hosts, | ||
| annotations: annotations, | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve hostless ingress catch-all behavior.
An omitted
IngressRule.Hostmeans that the rule applies to all inbound hosts. This extractor stores it as"", buthostMatchesHostnameandhostCoversNamenever match that value.updateFromItemtherefore removes all labelled apps from a valid hostless ingress. (kubernetes.io)Represent catch-all routing explicitly, or make both matching helpers treat an empty ingress host as matching every hostname.
🤖 Prompt for AI Agents