-
Notifications
You must be signed in to change notification settings - Fork 12
feat: ASPA path validation in rpki stage (RTR v2, RFC 9234 BGP Role) #33
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
Changes from all commits
5a6271c
1143f27
a17ef42
981ad60
394e7e0
61c57a4
b648abf
bb09fa0
630b38f
07f7b81
1b78449
741fc35
cbbf6da
fa27bcb
9bc0968
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,13 +3,16 @@ package core | |||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||
| "bytes" | ||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||
| "crypto/subtle" | ||||||||||||||||||||||||||||||||||
| "encoding/base64" | ||||||||||||||||||||||||||||||||||
| "encoding/json" | ||||||||||||||||||||||||||||||||||
| "errors" | ||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||
| "html" | ||||||||||||||||||||||||||||||||||
| "net" | ||||||||||||||||||||||||||||||||||
| "net/http" | ||||||||||||||||||||||||||||||||||
| "net/http/pprof" | ||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -26,6 +29,37 @@ func (b *Bgpipe) configureHTTP() error { | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| m := chi.NewRouter() | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // auth middleware (nil when no auth configured) | ||||||||||||||||||||||||||||||||||
| mw, err := b.httpAuthMiddleware() | ||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if mw != nil { | ||||||||||||||||||||||||||||||||||
| m.Use(mw) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // fixed routes | ||||||||||||||||||||||||||||||||||
| m.Get("/metrics", func(w http.ResponseWriter, r *http.Request) { | ||||||||||||||||||||||||||||||||||
| w.Header().Set("Content-Type", "text/plain; version=0.0.4; charset=utf-8") | ||||||||||||||||||||||||||||||||||
| vmmetrics.WritePrometheus(w, true) | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
| m.Get("/hc", func(w http.ResponseWriter, r *http.Request) { | ||||||||||||||||||||||||||||||||||
| w.Header().Set("Content-Type", "application/json") | ||||||||||||||||||||||||||||||||||
| json.NewEncoder(w).Encode(map[string]any{ | ||||||||||||||||||||||||||||||||||
| "status": "ok", | ||||||||||||||||||||||||||||||||||
| "version": b.Version, | ||||||||||||||||||||||||||||||||||
| "stages": b.StageCount(), | ||||||||||||||||||||||||||||||||||
| "uptime": time.Since(b.StartTime).Truncate(time.Second).String(), | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
| m.Get("/", b.httpDashboard) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // pprof | ||||||||||||||||||||||||||||||||||
| if err := b.configurePprof(m); err != nil { | ||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| b.httpmux = m | ||||||||||||||||||||||||||||||||||
| b.HTTP = &http.Server{ | ||||||||||||||||||||||||||||||||||
| Addr: addr, | ||||||||||||||||||||||||||||||||||
|
|
@@ -36,6 +70,110 @@ func (b *Bgpipe) configureHTTP() error { | |||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // httpAuthMiddleware returns middleware enforcing --http-auth. | ||||||||||||||||||||||||||||||||||
| // Returns nil if --http-open is set. Returns error if --http-auth is missing. | ||||||||||||||||||||||||||||||||||
| func (b *Bgpipe) httpAuthMiddleware() (func(http.Handler) http.Handler, error) { | ||||||||||||||||||||||||||||||||||
| if b.K.Bool("http-open") { | ||||||||||||||||||||||||||||||||||
| return nil, nil | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| authStr := strings.TrimSpace(b.K.String("http-auth")) | ||||||||||||||||||||||||||||||||||
| if authStr == "" { | ||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("--http requires --http-auth (or --http-open to disable auth)") | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| cred, err := b.readCredential(authStr) | ||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("--http-auth: %w", err) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| expected := []byte("Basic " + base64.StdEncoding.EncodeToString(cred)) | ||||||||||||||||||||||||||||||||||
| return func(next http.Handler) http.Handler { | ||||||||||||||||||||||||||||||||||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||||||||||||||||||||||||||||||||||
| if subtle.ConstantTimeCompare([]byte(r.Header.Get("Authorization")), expected) != 1 { | ||||||||||||||||||||||||||||||||||
| w.Header().Set("WWW-Authenticate", `Basic realm="bgpipe"`) | ||||||||||||||||||||||||||||||||||
| http.Error(w, "unauthorized", http.StatusUnauthorized) | ||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+80
to
+95
|
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| next.ServeHTTP(w, r) | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
| }, nil | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // readCredential reads a credential from a string, $ENV variable, or /path. | ||||||||||||||||||||||||||||||||||
| // The resolved value must be non-empty and contain a colon (user:pass). | ||||||||||||||||||||||||||||||||||
| func (b *Bgpipe) readCredential(v string) ([]byte, error) { | ||||||||||||||||||||||||||||||||||
| var cred []byte | ||||||||||||||||||||||||||||||||||
| switch { | ||||||||||||||||||||||||||||||||||
| case len(v) > 1 && v[0] == '$': | ||||||||||||||||||||||||||||||||||
| val := os.Getenv(v[1:]) | ||||||||||||||||||||||||||||||||||
| if val == "" { | ||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("environment variable %s is empty or unset", v) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| cred = bytes.TrimSpace([]byte(val)) | ||||||||||||||||||||||||||||||||||
| case len(v) > 0 && v[0] == '/': | ||||||||||||||||||||||||||||||||||
| fh, err := os.Open(v) | ||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| buf := make([]byte, 128) | ||||||||||||||||||||||||||||||||||
| n, err := fh.Read(buf) | ||||||||||||||||||||||||||||||||||
| fh.Close() | ||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("file %s: %w", v, err) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| line, _, _ := bytes.Cut(buf[:n], []byte{'\n'}) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+114
to
+124
|
||||||||||||||||||||||||||||||||||
| fh, err := os.Open(v) | |
| if err != nil { | |
| return nil, err | |
| } | |
| buf := make([]byte, 128) | |
| n, err := fh.Read(buf) | |
| fh.Close() | |
| if err != nil { | |
| return nil, fmt.Errorf("file %s: %w", v, err) | |
| } | |
| line, _, _ := bytes.Cut(buf[:n], []byte{'\n'}) | |
| buf, err := os.ReadFile(v) | |
| if err != nil { | |
| return nil, fmt.Errorf("file %s: %w", v, err) | |
| } | |
| line, _, _ := bytes.Cut(buf, []byte{'\n'}) |
Copilot
AI
Apr 3, 2026
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.
attachHTTPStages used to fail the pipeline setup if a stage’s RouteHTTP returned an error; it now only logs a warning and continues. If stage HTTP endpoints are expected to be reliable/mandatory, this can hide misconfigurations until runtime. Consider either keeping the original fail-fast behavior, or making the choice explicit via a flag/config so operators can decide.
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.
--pprofchanged from a boolean to a string ("http"vs separate address). There are existing docs in the repo that describe--pprofas a boolean flag; consider updating documentation/help text wherever it references the old behavior to avoid user confusion.