Skip to content

Conversation

sanikachavan5
Copy link
Contributor

@sanikachavan5 sanikachavan5 commented Sep 9, 2025

This pull request introduces security enhancements and configurability improvements for HTTP server timeouts in the agent and connect proxy, aiming to mitigate Slowloris and related denial-of-service attacks. It adds new configuration options for HTTP timeouts, ensures they are correctly parsed and validated, and updates both the agent and proxy to use these values. Comprehensive tests are added to verify correct behavior and edge cases.

Description

Security and HTTP Timeout Enhancements:

  • Added configuration options for HTTP server timeouts (read_timeout, read_header_timeout, write_timeout, idle_timeout) to HTTPConfig and RuntimeConfig, with sensible defaults and minimums, to protect against Slowloris and similar attacks (agent/config/config.go, agent/config/runtime.go, agent/config/builder.go, agent/agent.go). [1] [2] [3] [4]
  • Updated the agent's HTTP server initialization to use these configurable timeout values (agent/agent.go).
  • Updated the connect proxy's pprof HTTP server to use a configurable timeout (--pprof-timeout) and set minimums for security (command/connect/proxy/proxy.go). [1] [2] [3]

Testing & Reproduction steps

Links

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@sanikachavan5 sanikachavan5 requested a review from a team as a code owner September 9, 2025 18:40
@github-actions github-actions bot added theme/cli Flags and documentation for the CLI interface theme/config Relating to Consul Agent configuration, including reloading labels Sep 9, 2025
@sanikachavan5 sanikachavan5 added backport/all Apply backports for all active releases per .release/versions.hcl backport/ent/1.18 Changes are backported to 1.18 ent backport/ent/1.19 Changes are backported to 1.19 ent backport/ent/1.20 backport to ent 1.20 labels Sep 9, 2025
@sanikachavan5 sanikachavan5 force-pushed the fix-slowloris-http-endpoints branch from 15b7ae5 to 50dfa2e Compare September 12, 2025 19:33
boruszak
boruszak previously approved these changes Sep 22, 2025
Copy link
Contributor

@boruszak boruszak left a comment

Choose a reason for hiding this comment

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

I reviewed the docs updates and left suggestions to align with style guidelines. Otherwise LGTM!


Refer to the [formatting specification](https://golang.org/pkg/time/#ParseDuration) for additional information.

#### Duration validation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#### Duration validation
#### Duration formatting validation


#### Duration validation

When configuring timeout and duration values, Consul validates the format and enforces minimum values where applicable. Invalid duration strings will cause the agent to fail to start with a descriptive error message.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
When configuring timeout and duration values, Consul validates the format and enforces minimum values where applicable. Invalid duration strings will cause the agent to fail to start with a descriptive error message.
When you configure timeout and duration values, Consul validates the formatting and enforces minimum values where applicable. When you use invalid duration strings, the agent will fail to start and the output will include a descriptive error message.

Comment on lines 94 to 98
**Valid examples:**
- `"10s"` - 10 seconds
- `"1.5m"` - 1.5 minutes (90 seconds)
- `"2h30m45s"` - Complex duration with hours, minutes, and seconds
- `"0s"` - Zero duration (where allowed)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
**Valid examples:**
- `"10s"` - 10 seconds
- `"1.5m"` - 1.5 minutes (90 seconds)
- `"2h30m45s"` - Complex duration with hours, minutes, and seconds
- `"0s"` - Zero duration (where allowed)
**Examples of valid duration formatting**:
- `"10s"` - 10 seconds
- `"1.5m"` - 1.5 minutes, equivalent to 90 seconds (`90s`)
- `"2h30m45s"` - Complex duration with hours, minutes, and seconds
- `"0s"` - Zero duration, although not all fields support this value.

Comment on lines 100 to 105
**Invalid examples that will cause errors:**
- `"10"` - Missing unit specification
- `"10x"` - Invalid unit (`x` is not a recognized unit)
- `""` - Empty string
- `"abc"` - Non-numeric string
- `"-5s"` - Negative durations (not accepted for timeout configurations)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
**Invalid examples that will cause errors:**
- `"10"` - Missing unit specification
- `"10x"` - Invalid unit (`x` is not a recognized unit)
- `""` - Empty string
- `"abc"` - Non-numeric string
- `"-5s"` - Negative durations (not accepted for timeout configurations)
**Examples of invalid formatting that produce errors**:
- `"10"` - Missing unit specification
- `"10x"` - Invalid unit, as `x` is not a recognized duration
- `""` - Empty string
- `"abc"` - Non-numeric string
- `"-5s"` - Negative durations are not accepted for timeout configurations

- `"abc"` - Non-numeric string
- `"-5s"` - Negative durations (not accepted for timeout configurations)

**Minimum value enforcement:** Some timeout configurations enforce minimum values to prevent misconfigurations that could cause connection issues or security vulnerabilities. For example, handshake timeouts typically require a minimum of 1 second. When a configured value is below the minimum, Consul will report a validation error during startup.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
**Minimum value enforcement:** Some timeout configurations enforce minimum values to prevent misconfigurations that could cause connection issues or security vulnerabilities. For example, handshake timeouts typically require a minimum of 1 second. When a configured value is below the minimum, Consul will report a validation error during startup.
Some timeout configurations enforce minimum values to prevent connection issues or security vulnerabilities. For example, handshake timeouts typically require a minimum of 1 second. When a configured value is below the minimum, Consul reports a validation error during startup.

@boruszak boruszak added backport/1.21 Changes are backported to 1.21 backport/ent/1.21 changes are backported to 1.21 ent and removed backport/all Apply backports for all active releases per .release/versions.hcl backport/ent/1.18 Changes are backported to 1.18 ent backport/ent/1.19 Changes are backported to 1.19 ent backport/ent/1.20 backport to ent 1.20 labels Sep 22, 2025
nitin-sachdev-29 and others added 6 commits September 23, 2025 14:33
…22741)

* - Added support for IPv6 virtual IP offset calculation and validation.
- Upgraded `github.com/miekg/dns` dependency to v1.1.68.
- Included `BindAddr` in agent endpoint and enabled binding logic in IP offset calculations.
- Updated `go.mod` and `go.sum` to reflect dependency changes.

* Refactored `addIPOffset` to utilize `BindAddr` and introduced `getAgentBindAddr` for improved binding logic and IP offset calculation.
Added utility function isDualStack

* Executed go mod tidy

* Refactored network utilities into `netutil` package and updated `catalog.go` to use new functions for improved modularity and clarity. Removed duplicate implementations of `GetAgentConfig` and `isDualStack`.

* Added comprehensive unit tests for `netutil` package covering `GetAgentConfig`, `GetAgentBindAddr`, and `IsDualStack`. Refactored functions to support mocking for improved testability.

* only retaining utility function changes.

* added changelog
* "Get started" section redirects

* deploy & secure

* Consul operations complete

* register & discover

* Finish service networking

* Enterprise, Runtimes, and Plugins sections

* Reference docs
* Adding private key JWT support for OIDC
sreeram77 and others added 11 commits September 23, 2025 14:33
)

* update: default proxy BindAddress to :: for IPv6 agent bind addr

* add: changelog

* fixing conflicts

---------

Co-authored-by: Mukul Anand <[email protected]>
…22788)

fix: suppress lacks token permission while checking dual stack
redhat image version revert to 9.6
* fix path cleaning of proxied urls

* add changelog

* added more tests

* add tests and address review comments

* address review changes
use hardcoded names for preventing attacks
1. Support for registering a service with multiple named ports
2. The named ports can be used in DNS queries to discover ports based on usecase
@sanikachavan5
Copy link
Contributor Author

@boruszak I have made the required changes, can you take a look?
@dduzgun-security please take a look, conflicts are resolved.

Copy link

@santoshpulluri santoshpulluri left a comment

Choose a reason for hiding this comment

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

Please update the description.

Copy link
Contributor

@boruszak boruszak left a comment

Choose a reason for hiding this comment

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

Docs LGTM!

Approved on behalf of consul-docs

}

tempDir := testutil.TempDir(t, "consul")
tempDir, err := os.MkdirTemp("", "consul_sock_test_")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any specific reason why we moved away from the testutil.TempDir function?

// Use minimum timeout values for security while respecting user configuration
readTimeout := c.pprofTimeout
if readTimeout < 1*time.Second {
readTimeout = 1 * time.Second
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is a default of 1 second enough for the pprof timeout?

require.Contains(r, err.Error(), "EOF")
// After adding timeouts to prevent slowloris attacks, the connection
// times out with "i/o timeout" instead of "EOF"
if !strings.Contains(err.Error(), "EOF") && !strings.Contains(err.Error(), "i/o timeout") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure about this condition. Can we check to see the returned value from err.Error() and adjust the tests accordingly to use require.Contains like before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/ent/1.21 changes are backported to 1.21 ent backport/1.21 Changes are backported to 1.21 theme/cli Flags and documentation for the CLI interface theme/config Relating to Consul Agent configuration, including reloading
Projects
None yet
Development

Successfully merging this pull request may close these issues.