Bugs/agent gateway #2630
No reviewers
Labels
No labels
1week
2weeks
Failed compliance check
IP cameras
NATS
Possible security concern
Review effort 1/5
Review effort 2/5
Review effort 3/5
Review effort 4/5
Review effort 5/5
UI
aardvark
accessibility
amd64
api
arm64
auth
back-end
bgp
blog
bug
build
checkers
ci-cd
cleanup
cnpg
codex
core
dependencies
device-management
documentation
duplicate
dusk
ebpf
enhancement
eta 1d
eta 1hr
eta 3d
eta 3hr
feature
fieldsurvey
github_actions
go
good first issue
help wanted
invalid
javascript
k8s
log-collector
mapper
mtr
needs-triage
netflow
network-sweep
observability
oracle
otel
plug-in
proton
python
question
reddit
redhat
research
rperf
rperf-checker
rust
sdk
security
serviceradar-agent
serviceradar-agent-gateway
serviceradar-web
serviceradar-web-ng
siem
snmp
sysmon
topology
ubiquiti
wasm
wontfix
zen-engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
carverauto/serviceradar!2630
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refs/pull/2630/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from GitHub pull request.
Original GitHub pull request: #2223
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/2223
Original created: 2026-01-04T23:53:32Z
Original updated: 2026-01-05T01:03:59Z
Original head: carverauto/serviceradar:bugs/agent_gateway
Original base: testing
Original merged: 2026-01-05T01:03:57Z by @mfreeman451
User description
IMPORTANT: Please sign the Developer Certificate of Origin
Thank you for your contribution to ServiceRadar. Please note, when contributing, the developer must include
a DCO sign-off statement indicating the DCO acceptance in one commit message. Here
is an example DCO Signed-off-by line in a commit message:
Describe your changes
Issue ticket number and link
Code checklist before requesting a review
PR Type
Enhancement, Tests
Description
Refactored agent architecture to support push-based gateway communication instead of pull-based approach
Added
GatewayClientfor agent-to-gateway gRPC communication with reconnection and backoff logicImplemented
PushLoopfor periodic agent status pushing with enrollment, config polling, and state managementExtended protobuf definitions with new gateway communication messages (
GatewayStatusRequest,GatewayStatusResponse,GatewayStatusChunk) and agent configuration messages (AgentHelloRequest,AgentHelloResponse,AgentConfigRequest,AgentConfigResponse)Added new
AgentGatewayServicegRPC service withHello,GetConfig,PushStatus, andStreamStatusmethodsImplemented NATS account management service with JWT/NKey cryptographic operations for operator bootstrap, tenant account creation, and user credential generation
Added
NATSAccountServicegRPC service with six RPC methods for NATS JWT signing operationsImplemented NATS operator management with key generation and JWT signing capabilities
Added comprehensive test suites for NATS account service (474 lines) and user credential generation (440 lines)
Updated agent
Serverstruct to remove listener-based architecture and add gateway configuration fields (GatewayAddr,GatewaySecurity,PushInterval,TenantID,TenantSlug)Added NATS credentials file support in event writer service
Added CLI handlers for NATS bootstrap operations and account management
Added Elixir production configuration files for both core and agent-gateway applications
Diagram Walkthrough
File Walkthrough
9 files
monitoring.pb.go
Add gateway communication and agent configuration proto messagesproto/monitoring.pb.go
monitoring.prototoproto/monitoring.protoin source commentfile_monitoring_proto_*tofile_proto_monitoring_proto_*forconsistency
gateway_idfield toStatusRequest,ResultsRequest,StatusResponse, andResultsResponsemessagesgateway_idfield toResultsResponsewith getter methodGatewayStatusRequest,GatewayStatusResponse, andGatewayStatusChunkfor agent-to-gatewaycommunication
GatewayServiceStatusmessage type to represent individualservice status in gateway requests
AgentHelloRequest,AgentHelloResponse,AgentConfigRequest,AgentConfigResponse, andAgentCheckConfigAgentGatewayServicegRPC service with methods:Hello,GetConfig,PushStatus, andStreamStatusnats_account_grpc.pb.go
Add NATS account service gRPC definitionsproto/nats_account_grpc.pb.go
management
NATSAccountServicewith six RPC methods:BootstrapOperator,GetOperatorInfo,CreateTenantAccount,GenerateUserCredentials,SignAccountJWT, andPushAccountJWThandling and interceptor support
JWT signing operations
types.go
Refactor agent server for push-based gateway architecturepkg/agent/types.go
proto.UnimplementedAgentServiceServerembedding fromServerstruct (no longer needed for push-mode architecture)
listenAddrfield fromServerstructListenAddrfield fromServerConfigstructGatewayAddr,GatewaySecurity, andPushIntervalfor push-based architectureTenantIDandTenantSlugfortenant routing
Securityfield tag fromhot:"rebuild"toomitemptyforconsistency
Servercoordinates checkers and
PushLoophandles gateway communicationnats_bootstrap.go
CLI handlers for NATS bootstrap and account managementpkg/cli/nats_bootstrap.go
nats-bootstrap,admin nats generate-bootstrap-token, andadmin natsstatussubcommandsinitialization, system account generation, and platform account setup
and credential files with proper file permissions
configuration and tenant listing functionality
nats_account_service.go
gRPC service implementation for NATS account operationspkg/datasvc/nats_account_service.go
NATSAccountServergRPC service for NATS JWT/NKeycryptographic operations with stateless design
generation, and JWT signing capabilities
via
$SYSsubjectand proper connection lifecycle management
push_loop.go
Agent push loop implementation for gateway communicationpkg/agent/push_loop.go
PushLoopfor periodic agent status pushing togateway
services and checkers
interval and enrollment status
detection logic
operator.go
NATS operator management and JWT signing implementationpkg/nats/accounts/operator.go
capabilities
Operatorstruct for managing operator keys and signingaccount claims
importing existing ones
keys with base64 encoding support
gateway_client.go
Gateway client for agent-gateway gRPC communicationpkg/agent/gateway_client.go
GatewayClientfor agent-gateway communicationservice.go
NATS credentials file support in event writer servicepkg/consumers/db-event-writer/service.go
setup
NATSCredsFilepath before applying to connectionoptions
2 files
prod.exs
Add Elixir production configuration fileelixir/serviceradar_core/config/prod.exs
infofor production environmentruntime.exsprod.exs
Production configuration for Elixir applicationelixir/serviceradar_agent_gateway/config/prod.exs
level set to info
2 files
nats_account.pb.go
Generated protobuf code for NATS account serviceproto/nats_account.pb.go
message types and 1 enum
creation, user credential generation, and JWT signing
permissions, and resolver operations
methods
kv.pb.go
Proto file path normalization in generated codeproto/kv.pb.go
proto/kv.prototokv.protoinsource comments and descriptor variables
file_proto_kv_proto_*variable names tofile_kv_proto_*throughout the generated code
2 files
nats_account_service_test.go
NATS account service test suite with comprehensive coveragepkg/datasvc/nats_account_service_test.go
NATSAccountServerwith 474 lines oftest coverage
various configurations
and error handling
types, and user permissions
user_manager_test.go
User credential generation test suite with type-specific validationpkg/nats/accounts/user_manager_test.go
functionality
types
verification
generation
101 files
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/2223#issuecomment-3708545832
Original created: 2026-01-04T23:54:52Z
PR Compliance Guide 🔍
Below is a summary of compliance checks for this PR:
Sensitive secret exposure
Description: The newly added gRPC/protobuf API includes highly sensitive secrets in plaintext fields
(e.g.,
CreateTenantAccountResponse.account_seed,BootstrapOperatorResponse.operator_seed/system_account_seed,GenerateUserCredentialsResponse.creds_file_content, and request fields likeGenerateUserCredentialsRequest.account_seed), which can lead to credential/tenantcompromise if these RPCs are reachable without strict mTLS + strong
authentication/authorization and if responses/requests are logged or intercepted.
nats_account.pb.go [238-874]
Referred Code
🎫 No ticket provided
Codebase context is not defined
Follow the guide to enable codebase context checks.
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting
Status: Passed
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.
Status:
Audit logging unclear: The diff provided does not include the new NATS account service and gateway push handlers,
so it cannot be verified that critical actions (operator bootstrap, tenant account
creation, credential generation, JWT push) are consistently audit-logged with actor
identity, timestamp, action, and outcome.
Referred Code
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation
Status:
Error handling unverified: The diff provided does not include the new
GatewayClient,PushLoop, andNATSAccountServiceimplementations, so it cannot be verified that external-call failure paths (gRPC,
crypto/JWT ops, file I/O, reconnection/backoff) have complete contextual errors and
edge-case handling.
Referred Code
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.
Status:
Sensitive errors unverified: The service code returning errors for operations involving seeds/JWTs is not shown, so it
cannot be verified that user-facing errors do not expose sensitive details (e.g.,
revealing account existence or returning crypto parsing failures verbatim).
Referred Code
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.
Status:
Secret fields introduced: New protobuf messages include highly sensitive fields (e.g.,
account_seed,existing_operator_seed,creds_file_content), and without the corresponding handler/loggingcode it cannot be verified these values are never logged or emitted in structured logs.
Referred Code
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities
Status:
Input validation unverified: The PR introduces new external inputs via gRPC (tenant slug, seeds/JWTs, permissions,
mappings) but the diff does not include the server-side validation/authn/authz logic, so
secure validation and authorization of these sensitive operations cannot be confirmed.
Referred Code
Compliance status legend
🟢 - Fully Compliant🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/2223#issuecomment-3708547174
Original created: 2026-01-04T23:56:53Z
PR Code Suggestions ✨
Explore these optional code suggestions:
Re-evaluate building a custom NATS account service
The PR builds a custom NATS account and JWT management service. It is suggested
to re-evaluate this approach and consider using the official
nats-account-serverto reduce complexity and security risks.
Examples:
pkg/datasvc/nats_account_service.go [42-888]
proto/nats_account.pb.go [1-1266]
Solution Walkthrough:
Before:
After:
Suggestion importance[1-10]: 9
__
Why: The suggestion raises a critical architectural concern about implementing a custom, security-sensitive NATS account management service instead of using the official
nats-account-server, which could significantly impact the project's security and maintainability.Restrict overly permissive user permissions
Restrict the overly broad permissions for the platform user in
generatePlatformAccountfrom>to a specific list of subjects to enhancesecurity.
pkg/cli/nats_bootstrap.go [603-608]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 9
__
Why: This is a critical security suggestion that correctly identifies overly permissive permissions (
>) and proposes restricting them to only the necessary subjects, adhering to the principle of least privilege.Optimize payload by removing redundant fields
Remove redundant fields from the
GatewayServiceStatusmessage to optimizenetwork payloads and improve data consistency. This change should be applied to
the source
.protofile.proto/monitoring.pb.go [1514-1530]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies redundant fields in the
GatewayServiceStatusmessage, which can impact network payload size and data consistency, and rightly points out the change needs to be in the.protofile.Fix incorrect URL parsing logic
Fix a bug in
applyPortToPathLikewhere targets with a host and path (e.g.,example.com/path) are parsed incorrectly. The fix involves splitting the hostand path before parsing to ensure the URL is constructed correctly.
pkg/agent/push_loop.go [796-813]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies a bug in URL parsing for targets containing both a host and a path, and provides a valid fix. This improves the robustness of the check configuration logic.
Improve verification by ignoring commented lines
Improve the NATS configuration verification by parsing the file line-by-line,
ignoring empty or commented lines to prevent false positives from
strings.Contains.pkg/cli/nats_bootstrap.go [647-668]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies a bug where
strings.Containswould falsely validate commented-out configuration lines, and the proposed fix of parsing line-by-line while ignoring comments is a robust improvement to the verification logic.Enable graceful flag error handling
Replace
flag.ExitOnErrorwithflag.ContinueOnErrorin flag sets to enablegraceful error handling for malformed flags instead of exiting the program.
pkg/cli/nats_bootstrap.go [53]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 5
__
Why: The suggestion correctly points out that using
flag.ContinueOnErrorallows for more graceful error handling in a CLI application, which improves robustness and testability.Improve file existence checking
Enhance the file existence check by handling all errors from
os.Statandverifying that the provided path is a regular file, not a directory.
pkg/cli/nats_bootstrap.go [636-638]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 6
__
Why: This suggestion improves the robustness of the file verification by adding checks for non-existence errors and ensuring the path points to a regular file, not a directory, preventing potential runtime issues.
remove stale checker configs
Uncomment the logic in
applyChecksto remove stale checker configurations fromp.server.checkerConfs. This prevents configurations from accumulatingindefinitely after they are removed from the gateway.
pkg/agent/push_loop.go [657-664]
[To ensure code accuracy, apply this suggestion manually]Suggestion importance[1-10]: 5
__
Why: The suggestion correctly points out that commented-out code would prevent the cleanup of stale checker configurations, potentially leading to a memory leak. Uncommenting it improves the agent's long-term stability.