Commit Graph
100 Commits
Author SHA1 Message Date
Timothy Messier a2c529b9d1 fix(controller): Use max request duration cluster listener (#4805)
The cluster listener supports a `max_request_duration` option, and
defaults to 90 seconds. However, this configuration was not being use
when processing grpc requests from the listener. This meant that
requests from worker to controller could hang indefinitely and
contributed to the recently fixed issue with database connections being
stuck in `idle in transaction`.

This commit adds a grpc interceptor that ensures each request has a
deadline set to the max request duration for the listener.

Refs: 29cd7bc9d6
2024-05-17 11:59:50 -04:00
Timothy Messier 29cd7bc9d6 fix(session): Move encryption/decryption out of database transactions (#4803)
Several session.Repository methods need to encrypt or decrypt fields
when persisting or retrieving a Session. These encrypt/decrypt
operations where being performed while within a database transaction.

The first step in the encrypt/decrypt operation is to retrieve the
kms.Wrapper. While the wrappers get cached in memory, the retrieval
still results in a database query to check that the kms collection
version has not changed. This query happens with a separate db.Reader,
and therefore uses a separate database connection from the transaction
being used by the session.Repository.

If the controllers are configured with a relatively low
`max_open_connections`, and be under sufficient load interactive with
sessions, the controller can consume all of the available database
connections, and get stuck with open transactions while waiting for a
database connection to execute the kms related queries. This can be see
by checking pg_stat_activity and seeing transactions stuck in `idle in
transaction` with a wait_event of ClientRead.

This commit changes all of the Repository methods the perform any
encryption or decryption operations, including the retrieval of the
kms.Wrapper, outside of a database transaction. An alternative approach
would be to unsure that the kms.Wrapper retrieval happens within the
same database transaction. However, it seems preferable to avoid doing
these relatively expensive operations within a transaction when it is
not necessary.

As part of this fix, it also eliminates some logic that is no longer
needed. During previous would with KMS wrapping, the method of how
sessions were encrypted was changed, and some logic to lazily re-encrypt
sessions was introduced. However, given that terminated sessions are
deleted, and the KMS changes was introduced several versions ago
(0.13.0), this lazy re-encrypt logic should no longer be necessary.

Refs: edd323b73a
See:
    https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW
    https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-IDLE-IN-TRANSACTION-SESSION-TIMEOUT
    https://developer.hashicorp.com/boundary/docs/configuration/controller#max_open_connections
2024-05-16 08:45:45 -04:00
Timothy MessierandSorawis Nilparuk 7c14aeaf41 fix(session): Use active transaction (#4592)
When closing orphaned connections and checking if a session is not
active, the repository was opening a transaction, but then calling the
original reader instead of using the reader/writer from the transaction.
This would result in a transaction being opend, then a separate
transaction being used to run the query, and finally the original
transaction would commit without any statements being executed.

Co-authored-by: Sorawis Nilparuk (Bo) <sorawis.nilparuk@hashicorp.com>
2024-04-19 10:40:42 -07:00
Timothy Messier 3a8ee32140 doc: Add details on "river" formatting to SQL style guide (#4450) 2024-03-11 15:08:06 -04:00
Timothy Messier 3856573eeb Merge pull request #4445 from hashicorp/llb-monthly-active-users
This adds support for tracking and reporting monthly active users for
the purpose of billing. It adds a new API endpoint,
`/v1/billing:monthly-active-users` and new cli command, `boundary
billing monthly-active-users` that can be used to view the monthly
active user counts.

This adds a new accumulating fact table to the data warehouse for auth
tokens. This fact table is used to calculate the number of active users
within a month, where an active user is a user that has at least one
issued auth token within the time range of the month.
2024-02-23 11:07:51 -05:00
Timothy Messier 4b0e7ab5a3 chore(authtoken): Fix lint errors in tests 2024-02-23 16:06:36 +00:00
Timothy Messier 111dc87ead feat(billing): Fix end time comparision for all view 2024-02-23 15:44:10 +00:00
Timothy Messier e6c3795f91 refact(db): Renumber migrations for billing 2024-02-23 15:44:10 +00:00
Timothy Messier edfd8b5f54 feat(billing): Support -/+ infinity
This updates the billing repository to use timestmap.Timestamp when
constructing the queries to retrieve monthly active users. This allows
for specifying NegativeInfinity to easily retrieve all monthly active
user counts.
2024-02-23 15:44:10 +00:00
Timothy Messier 0f765e7149 feat(timestamp): Support -/+infinity for Valuer
When converting a timestamp.Timestamp for use in SQL, this now correctly
converts the NegativeInfinity and PositiveInfinity constants into the
corresponding `-infinity` and `infinity` SQL constants.
2024-02-23 15:44:10 +00:00
Timothy Messier e09bf09a95 refact(billing): Use sql functions instead of views
These functions will ensure that UTC time is used for billing queries,
eliminating the need for the repository to set the timezone. This also
means the repository no longern needs a writer.
2024-02-23 15:44:09 +00:00
Timothy Messier 7c14e42897 refact(census): Make emitting events stateful for a census job 2024-02-23 15:44:09 +00:00
Timothy Messier a4b34f67c8 feat(census): Add support for multiple metrics 2024-02-23 15:44:09 +00:00
Timothy Messier 5405a275ab feat(census): Update census tables to support additional metrics 2024-02-23 15:44:09 +00:00
Timothy Messier 5aafe66c3c test(ratelimit): Update tests due to new endpoint 2024-02-23 15:44:09 +00:00
Timothy Messier d84eb01516 feat(billing): Add sql functions for monthly active user counts
This adds two sql functions that can be used to access the views to
retrieve monthly active user counts. The functions ensure that any time
calculates are performed in UTC, so that the month bounds align with the
start of the month in UTC.

1. hcp_billing_monthly_active_users_last_2_months() will return monthly
   active users for the current and previous month.
2. hcp_billing_monthly_active_users_all() will return monthly active
   users for all months. This function can also be provided a start time
   and or end time to filter the results to a specific range.
2024-02-23 15:44:09 +00:00
Timothy Messier 324c474f5d feat(billing): Add views for monthly active user counts 2024-02-23 15:44:09 +00:00
Timothy Messier f3caf21979 test(authtoken): Associate test account with a user
This test started failing now that the data warehouse records a auth
token fact when an auth token is issued and it requires that the auth
token has a user associated with it.

Since this test is testing the interaction with the database directly,
and not via the repository, it by-passes the application checks that
would prevent an auth token without an associated user being inserted.

This test is updated to meet this same pre-condition prior to attempting
to insert into the database.
2024-02-23 15:44:09 +00:00
Timothy Messier bbb43e20a0 test(sqltest): Remove impossible assertion
Now that there is an auth token fact table in the data warehouse, it is
not possible to insert an auth_token with an old public_id even after
that auth_token was deleted, since it now causes a constraint violation
on the data warehouse table.
2024-02-23 15:44:09 +00:00
Timothy Messier 9514a76289 test(sqltest): Fix tests due to new auth_token insert trigger
With the addition of an after insert trigger to the auth_token table,
entries are added to the wh_user_dimension table when auth token's are
inserted with the 'token issued' status. This caused a number of tests
to fail that assumed the user dimension table would be empty prior to
inserting sessions. This introduces a number of changes to the tests:

- In the test setup, auth tokens are not created with an explicit
  expiration time and status. The expiration time ensures that the
  tokens are 'valid' for the test. The status allows test to make
  assertions on tokens in different statuses, and allow the status to
  change during the test.
- Tests make the correct assertions on the number of entries in the user
  dimension table after test setup.
- User dimension tests modify a user after the standard setup to ensure
  that a new user dimension is added when a session is inserted.
2024-02-23 15:44:08 +00:00
Timothy Messier 9e0d96b887 feat(dw): Update auth token fact when auth token is deleted
This adds a function and after delete trigger to the auth_token table to
ensure that a corresponding auth token fact is updated with the deleted
time and sets the auth token valid time range. The data warehouse will
only be updated if the token that was deleted is in the 'token issued'
status.
2024-02-23 15:44:08 +00:00
Timothy Messier b938dd6706 feat(dw): Insert/update auth token fact when auth token updated
This adds a function and update trigger to auth_token to ensure that:

1. If the auth token is updated to the issued state, a auth token fact
   is added to the warehouse.
2. If the auth token's approximate last access time is updated, the
   corresponding auth token fact is updated with the new time.
2024-02-23 15:44:08 +00:00
Timothy Messier 585b344da6 feat(auth_token): Set approximate_last_access_time when token is issued 2024-02-23 15:44:08 +00:00
Timothy Messier 07b3a7a19e feat(dw): Add auth token fact after inserting issued auth token
This adds a trigger and function to ensure that an auth token fact is
created when a new auth token is created with the 'token issued' status.
2024-02-23 15:44:08 +00:00
Timothy Messier eb626bb54c refact(wh): Use auth token id for user dimension
Previously the function used to upsert into the user dimension required
both an auth token id, and a user id. However, the user id can be
determined from the auth token, in fact it already was via the
whx_user_dimension_source view. This refactor removes the user id as an
argument, since it is not needed and will not be directly available when
this function is used when populating the new auth token accumulating
fact.
2024-02-23 15:44:08 +00:00
Timothy Messier 03d1cc4572 feat(dw): Add auth token accumulating fact table 2024-02-23 15:44:08 +00:00
Timothy Messier 005f3d0843 chore(sqltest): Make it possible to enable/disable db container logs
When running the sqltests, sometimes it is helpful to see the full
database container logs, especially when there is an error in a
migration or database setup. However, it also makes it difficult to see
the test results.

This adds a new variable to the makefile to easily toggle the output of
these logs on or off. To run the tests without printing the dtabase logs
use:

    DB_LOGS=0 make test

To enable the logs use:

    DB_LOGS=1 make test

By default the logs are not printed.
2024-02-23 15:44:08 +00:00
Timothy Messier e51d0e0b4f feat(vault): Remove database notice when setting credential type
This notice just generated noise, particuarlly in some of the sqltests.
2024-02-23 15:44:08 +00:00
Timothy Messier 9d82958c9f test(sqltest): Shorten prepared statement identifiers
Some of the prepared statement identifies used in these tests exceeded
the identifier character limit. This results in postgres truncating the
name, which is fine for a test, but does result in some noise in the
test output. This change shortens the identifies to eliminate noise like
the following:

    psql:/test/credential/vault/credential_vault_library_ssh_private_key_mapping_override.sql:49: NOTICE:  identifier "insert_credential_vault_library_ssh_private_key_mapping_override" will be truncated to "insert_credential_vault_library_ssh_private_key_mapping_overrid"

The tests should no longer create notices like these.
2024-02-23 15:44:08 +00:00
Timothy Messier af5779e92b Merge pull request #4254 from hashicorp/tmessi-disable-jit
Disable postgres JIT for boudary dev
2024-01-18 14:38:14 -05:00
Timothy Messier 1e51dbef4f feat(test): Add docker images for additional postgres versions 2024-01-18 19:37:46 +00:00
Timothy Messier e255284996 feat(test): Disable JIT for test database image 2024-01-18 19:37:46 +00:00
Timothy Messier 9c5c17a3ee feat(cmd): Disable postgres JIT for boundary dev
After updating `boundary dev` to use postgres:12 by default, it was
noticed that the responsiveness of boundary was noticeably slower. This
is due to the introduction of JIT being enabled by default in
postgres:12. JIT seems to incur noticeable overhead without providing
benefits, at least for the instance used for `boundary dev`.

It is also worth noting that for postgres:14 and newer, JIT does not get
triggered for the same queries since they seem to result in a cheaper
query plan that does not exceed the default threshold for JIT.

See:
    https://www.postgresql.org/docs/current/jit.html
    ICU-12283
2024-01-18 19:37:46 +00:00
Timothy Messier b3bc367534 feat(controller): Expose rate limiting headers via CORS (#4159)
This adds a Access-Control-Expose-Headers response header to an Options
request to allow the rate limiting related headers to be accessible via
requests that are subject to CORS.
2024-01-08 10:02:36 -05:00
Timothy Messier 64995854a3 feat(dbtest): Allow host to be configurable (#2538)
Normally the tests are run on a host machine with a docker container for
the database. The docker container should be accessible via 127.0.0.1.
However there might be cases where the test execution is run in a docker
container, or the postgres server is configured to use a different
docker network, in which case the container would be accessible via some
other dns name or ip. In these cases, users can now set the TEST_DB_HOST
environment variable so the tests can connect to the postgres server.
2024-01-05 10:34:51 -08:00
Timothy Messier 1bf883e4b1 chore(changelog): Add entry for 0.13.5 2023-12-12 21:14:01 +00:00
Timothy Messier 428cb4111c chore: Update changelog for 0.14.3 2023-12-12 21:09:19 +00:00
Timothy Messier a77c88ae5d feat(ratelimit): Increase default values (#4129)
This increases the default rate limits to:

- 1,500 reqs / 30 seconds for list actions in total
- 1,500 reqs / 30 seconds for list actions per IP address
- 150 reqs / 30 seconds for list actions per auth token

And for all other actions:

- 30,000 reqs / 30 seconds for list actions in total
- 30,000 reqs / 30 seconds for list actions per IP address
- 3,000 reqs / 30 seconds for list actions per auth token

This seems to be a reasonable default for a small to medium size cluster
based on some scale testing.

(cherry picked from commit 237c8b6084f42655edaba49055e511163fdf1c53)
2023-12-08 14:53:49 +00:00
Timothy Messier c70a6ff6ba chore: Bump to Go version 1.21.5
Go 1.21.5 fixes a few vulnerabilities. Most notably for boundary is a
fix in net/http to limit chunked data overhead.

See: https://groups.google.com/g/golang-announce/c/iLGK3x6yuNo
(cherry picked from commit 575cd9d63b1ac4787d048d86b0b209c61a7f3946)
2023-12-07 19:42:45 +00:00
Timothy Messier 52cab530f2 Merge pull request #4092 from hashicorp/llb-rate-limiting
Add support for rate limiting

This introduces rate limiting for the Controller API endpoints. Limits
can be set separately for each combination of resource and action. And
each combination has a limit per auth-token, IP address, and in total.

By default each list action for all resources has a limit of 120
requests per minute. All other actions for all resources have a limit of
3,000 requests per minute. This can be overridden by including
`api_rate_limit` stanzas in the controller configuration. For example to
set a limit on target list requests per auth token:

    controller {
      api_rate_limit {
            resources = ["target"]
            actions   = ["list"]
            per 	= "auth-token"
            limit 	= 10
            period	= "1s"
      }
      // other controller configuration
    }

Or to completely override all of the defaults:

    controller {
      // total limit for all resources and actions
      api_rate_limit {
            resources = ["*"]
            actions   = ["*"]
            per  	= "total"
            limit 	= 500
            period	= "1s"
      }

      // limit for ip addresses to all resources and actions
      api_rate_limit {
            resources = ["*"]
            actions   = ["*"]
            per 	= "ip-address"
            limit 	= 100
            period	= "1s"
      }

      // Limit for auth tokens to all resources and actions
      api_rate_limit {
            resources = ["*"]
            actions   = ["*"]
            per 	= "auth-token"
            limit 	= 50
            period	= "1s"
      }
      // other controller configuration
    }

All rate limiting can be disabled by setting the
`api_rate_limit_disable` configuration variable:

    controller {
      api_rate_limit_disable = true
      // other controller configuration
    }

When rate limiting is enabled, boundary will create quotas to track the
number of requests used within a time period. Boundary will reserve a
set amount of memory for tracking quotas. This ensures that boundary
does not consume too much memory if there is a sudden burst of requests
from many different clients. However this does mean if boundary is
unable to store a quota, it will limit the request with a 503 HTTP
status code. The amount of memory can be controlled with the
`api_rate_limit_max_quotas` configuration variable. This can also be
monitored via two new metrics:

- `boundary_controller_api_ratelimiter_quota_storage_capacity`
- `boundary_controller_api_ratelimiter_quota_storage_usage`

Clients making requests to the controller API can inspect HTTP response
headers to understand the configured limits and current usage. Each
response will contain the following headers:

- RateLimit: Provides the current limit, number of remaining requests,
  and the time the quota will reset for the limit that is closest to
  being exhausted for the requested resource and action.
- RateLimit-Policy: Describes the limits for the requested resource and
  action.

If a request is limited, the client will receive a 429 HTTP status code,
and the Retry-After header will be set to the number of seconds the
client should wait before attempting the request again.
2023-12-05 08:06:23 -05:00
Timothy Messier 758e7b8bf1 test(credentials): Disable rate limiting for test
This test quickly polls a list endpoint, which exceeds the default rate
limits before the test can complete in CI.
2023-12-04 22:40:39 +00:00
Timothy Messier cd21f10a3b chore(lint): Update version of golangci-lint
Updating this helps resolve some false positives that were happening in
CI when detecting linter issues on PRs.
2023-12-04 22:23:50 +00:00
Timothy Messier a7730b02ac test(host_catalog): Fix flaky assertion 2023-12-04 21:38:31 +00:00
Timothy Messier 6e233c879f fix(ratelimit): Round up when setting Retry-After header
Previously this would truncate to the nearest integer, which could
result in clients retrying before the quota has reset, and getting rate
limited again. This also includes an update from go-rate that will round
up when reporting the reset time for the RateLimit header.

Note that in the case of a 503, the Retry-After header was already being
set correctly.

See: https://github.com/hashicorp/go-rate/pull/8
2023-12-04 21:35:20 +00:00
Timothy Messier da5dd383ad feat(api): Use Retry-After header when retrying a request
If the api.Client receives a 429 or 503 along with a Retry-After header,
the client will automatically wait the amount of time specified, and
then re-try the request.
2023-12-04 18:07:01 +00:00
Timothy Messier 35b91c66de refact(ratelimit): Rename MaxEntries to MaxQuotas 2023-12-04 17:25:16 +00:00
Timothy Messier a150c588bb feat(controller): Emit sys event detailing the rate limit configuration
A sys event will be emitted when the controller is constructed, and if
the rate limits are changed via a SIGHUP. The event contains the details
of the rate limits for each combination of resource and action. This
event can be used by operators to confirm the limits are set as they
would expect based on the controller config.
2023-12-04 16:24:20 +00:00
Timothy Messier 9438be4506 feat(ratelimier): Support disabling rate limiting 2023-12-04 16:24:20 +00:00
Timothy Messier d0c3da5f1d refact(ratelimiter): Updates due to refactor in go-rate 2023-12-04 16:24:19 +00:00
Timothy Messier 3c2bed92b0 feat(ratelimit): Expose metrics on quota usage
This provides two prometheus metrics to monitor the rate limiter:

boundary_controller_api_ratelimiter_quota_storage_capacity:

This is a gague that shows the total number of quotas that can be stored
at a given moment by the rate limiter.

boundary_controller_api_ratelimiter_quota_storage_usage:

This is a gague that shows the number of quotas currently being stored
by the limiter. If this becomes equal to the capacity, requests that
would result in a new quota being created will get limited and receive a
429 status code.
2023-12-04 16:24:04 +00:00
Timothy Messier 0bc423ebd8 feat(controller): Reload api rate limits on SIGHUP 2023-12-04 16:24:04 +00:00
Timothy Messier f54f2c0fc4 fix(ratelimit): Correctly extract ids from paths with punctuation 2023-12-04 16:24:04 +00:00
Timothy Messier 26854b01a8 feat(ratelimit): Set RateLimit and RateLimit-Policy headers 2023-12-04 16:24:04 +00:00
Timothy Messier e337cf8f69 feat(controller): Add authtoken public id to request context
This allows for http middleware handler functions that run later in the
handler function stack to have access to the extracted auth token public
id.
2023-12-04 16:24:04 +00:00
Timothy Messier 059d4992de feat(ratelimit): Add support for limits per ip address and auth token 2023-12-04 16:24:00 +00:00
Timothy Messier 00bd2899af feat(controller): Add ratelimiter http middleware 2023-12-04 16:22:58 +00:00
Timothy Messier 2853324479 feat(ratelimit): Add http middleware handler function 2023-12-04 16:20:44 +00:00
Timothy Messier 6da47443fd feat(ratelimit): Create rate limits from configs 2023-12-04 16:20:44 +00:00
Timothy Messier 61fcd857ec feat(resource): Add function to get type from plural string 2023-12-04 16:20:44 +00:00
Timothy Messier bc48e58035 chore: Add go-rate dependency 2023-12-04 16:20:42 +00:00
Timothy Messier 51adde4b2c feat(handlers): Register actions for each resource type
This registers the ActionSets for each resource when the handler
packages are initialized. This then allows other packages to retrieve
the ActionSets for a given resource from the action package.

The initial consumer of this will be the ratelimit package so that it
can programmatically enumerate all of the valid combinations of a
resource and action.

This leaves a number of TODO to refactor the handler packages to also
retrieve the action sets from the registered actions instead of using a
package variable. This is left as a TODO since there is some
inconsistencies in how these package variables are used between the
handlers. For example a number of packages use a map of subtypes to
ActionSets which is then used withing the handler implementation. Others
use a map, but don't seem to use it at all. And others just use an
ActionSet.
2023-12-04 16:20:29 +00:00
Timothy Messier 3f4a723541 feat(action): Add registrar for valid actions by resource 2023-12-04 16:20:29 +00:00
Timothy Messier 8643d8e6c6 feat(errors): Add code for invalid configuration 2023-12-04 16:20:29 +00:00
Timothy Messier c52caae345 refact(action): Make ActionSet behave as a set instead of a list
This switches the implementation of an ActionSet from a slice to a map
to ensure the elements in an ActionSet are unique. This allows for other
packages to perform set operations such as a union or difference without
needing to account for duplicates.
2023-12-04 16:20:29 +00:00
Timothy Messier bee45dc486 feat(config): Add fields for controller rate limit configuration 2023-12-04 16:20:28 +00:00
Timothy Messier 0fb77358e5 feat(ratelimit): Define initial ratelimit package and Config 2023-12-04 16:20:28 +00:00
Timothy Messier dd23f6fdbf Update websocket library (#3908)
The nhooyr/websocket library now has a release with the new default
behavior that removes the message size limit. This allows us to switch
off of the fork and back to the upstream.

In the same release that includes the fix we need for the boundary
client, the wspb helper package was removed from websocket. This package
contained some functions to read and write protobuf messages. However,
it was using the deprecated github.com/golang/protobuf/proto library. To
avoid this dependancy in the library they opted to just remove wspb.

Thus this provides a replacement implementation that uses
google.golang.org/protobuf/proto. Notably the newer proto library seems
to lack an equivalent of proto.NewBuffer so writes to the websocket and
not able to leverage a sync.Pool of byte.Buffers to reduce allocations.

Refs: 88bb253554
See: https://github.com/nhooyr/websocket/commit/ac385120c6e34fa6584f3856d5db949a21bbb65e
2023-11-06 14:59:11 -05:00
Timothy Messier d865ff16a4 ci(schema-diff): Fix error with large diffs (#3909)
When generating the JSON for submitting the github comment, if the
message was too large, the workflow would fail with the following error:

    /usr/bin/jq: Argument list too long

This fix switches to using the `--rawfile`, which allows jq to process
the large comment.
2023-10-24 14:00:29 -04:00
Timothy Messier 88bb253554 fix(cli): Remove websocket message size limit (#3808)
When the boundary client establishes a connection to the websocket used
to communicate with a worker, it was configured with a max websocket
message size of 32KiB. This was the default behavior for v1.8.7 of
nhooyr/websocket. However, there are cases where the worker can send
messages to the client that are larger than 32KiB. When this happens the
client returns an error and terminates the connection.

Notably this seems to only currently impact sessions made to SSH
Targets, although it could theoretically impact any target type
depending on the details of how the worker performs the writing of the
messages. The issue can be reproduced by attempting to scp a large
enough file from an SSH Target to the client. In this case the
connection gets terminated and results in a partial transfer of the
file.

This message size limit appears to be unnecessary, and the default
behavior is changing in v1.8.8 of nhooyr/websocket to make the message
size unlimited. Since this version is not yet released, this commit
switches the dependency to a fork with a version that is v1.8.7 plus the
patch to disable the limit. Once v1.8.8 is release this dependency can
be set back.

See:
    https://github.com/nhooyr/websocket/pull/254
    https://github.com/nhooyr/websocket/pull/256
2023-10-06 11:45:29 -04:00
Timothy Messier c9b043a14b chore(ci): Remove install script for golangci-lint (#3789)
Just run a known version from the official repository.
2023-10-02 16:43:09 -04:00
Timothy Messier af92f20633 chore: Use version/VERSION as single source of version number
This updates the version make target to use the version/VERSION file in
the same manner as the build system. This ensures that the VERSION file
is the single source of truth for the version number.
2023-08-02 17:27:47 +00:00
Timothy Messier 2d81103ef5 doc(docker): Separate docker.io readme contents from directory readme (#3308)
This moves the contents of the readme used for hashicorp/boundary on
docker.io/registry.hub.docker.com to a separate readme file from the one that
documents how to build docker images. It also makes some minor fixups
and updates the docker.io readme, must notably updating the minimum
version of postgres that boundary requires.
2023-06-12 15:31:27 -04:00
Timothy Messier 837734b745 test(bsr/fstest): Add new FS for testing out of space errors (#3305)
This provides a new storage.FS implementation that expands the on
fstest.MemFS by allowing tests to mark the filesystem as out of space.
When this happens any write/create operation will start returning an
error indicating that the filesystem is out of space.
2023-06-09 16:32:24 -04:00
Timothy Messier fe7c87dc82 feat(bsr/ssh): Add open failure details to ChannelSummary (#3297) 2023-06-08 11:17:32 -04:00
Timothy Messier f7386a5d53 Merge pull request #3280 from hashicorp/tmessi-fix-session-list
fix(session): List performance with large number of session connections

This includes the backported migration and a migration to ensure the next
release has the correct view.
2023-06-06 14:34:15 -04:00
Timothy Messier 603642f271 fix(session): List performance with large number of session connections (#3288)
As part of the performance improvements for listing sessions for v0.9.0,
the view used to retrieve sessions for listing was updated to no longer
include a join on session_connection. However, a later migration that
was adding additional columns to this view inadvertently re-added the
join and session_connection columns. This resulted in requests to list
sessions performing this join, and returning additional rows for each
connection in a session. The application would ignore this additional
data, since it is no longer returned via the API. This would be
particularly impactful in cases where there are a large number of
connections per session, as this would greatly increase the amount of
data returned by the database.

This fix removes the session_connection join from this view, which
should restore the original performance improvements even in cases where
there is a large number of session connections per session.

See: https://github.com/hashicorp/boundary/pull/2160
Ref: 32070678dc
Fixes: 1e3c941be1

(cherry picked from commit 7aef341682e65b42c1b919e03936bdf81e26e87c)
2023-06-06 17:45:53 +00:00
Timothy Messier 876f9bb07f fix(session): List performance with large number of session connections
As part of the performance improvements for listing sessions for v0.9.0,
the view used to retrieve sessions for listing was updated to no longer
include a join on session_connection. However, a later migration that
was adding additional columns to this view inadvertently re-added the
join and session_connection columns. This resulted in requests to list
sessions performing this join, and returning additional rows for each
connection in a session. The application would ignore this additional
data, since it is no longer returned via the API. This would be
particularly impactful in cases where there are a large number of
connections per session, as this would greatly increase the amount of
data returned by the database.

This fix removes the session_connection join from this view, which
should restore the original performance improvements even in cases where
there is a large number of session connections per session.

See: https://github.com/hashicorp/boundary/pull/2160
Ref: 32070678dc
Fixes: 1e3c941be1
2023-06-06 17:45:30 +00:00
Timothy Messier 7e094d824f feat(bsr/convert): Remove asciicast minimum window size (#3287)
This removes the minimum on width and height, instead it will just used
the largest width, height seen as the initial size for the asciicast.
This also provides the ability to still set a minimum via options to
convert.ToAsciicast if the caller has a known minimum size. Also note
that in cases where there is no size information, ie if there was no pty
request, this will still pick a default size of 80x24.
2023-06-06 12:26:46 -04:00
Timothy Messier 75ef443ae1 chore: Update api and sdk tags 2023-06-01 15:11:57 +00:00
Timothy Messier 84b96f89a7 chore: Bump version 2023-05-31 16:01:03 +00:00
Timothy Messier 61a37ef4a4 fix(schema): Add missing endpoint column to session recording view 2023-05-31 15:53:16 +00:00
Timothy Messier f64f03ed46 fix(targets): Support authorize session request with target name (#3252)
For requests to the target authorize session endpoint we support passing
a target name instead of an id. This means that `req.GetId()` might not
be the target's public id. Since the first thing authorize session does
includes retrieving the target as part of the authorization checks, this
subtype check can leverage the public id of the target instead of using
the request.

Fixes: 6178dd516e
2023-05-31 11:25:03 -04:00
Timothy Messier c2da88d2a5 test(cmd/config): Fix test compilation error
Refs: 9ae2bdfae
2023-05-31 12:47:20 +00:00
Timothy Messier 29b9a508a3 chore(lint): Ignore warning about deprecated field
This is being explicitly tested until it is removed, so this silences
the linter for this specific case.
2023-05-31 12:18:24 +00:00
Timothy Messier cdf18b6369 test(cli/targets): Add test case for default client port 2023-05-31 12:18:24 +00:00
Timothy Messier 9f2c83f3b0 refact(bsr): Rename const to denote when interpolation is needed 2023-05-31 12:18:23 +00:00
Timothy Messier b88b4cce75 feat(bsr/ssh): Add file transfer direction to channel summary
When an SSH channel is used for a file transfer, the summary will report
the detected direction of the file transfer as either an upload or
download, relative to the end client.
2023-05-31 12:18:23 +00:00
Timothy Messier 78ea1a9f3a refact(bsr): Use JSON for session meta and summary data
The session metadata is provided all at once when a new bsr is opened.
While the session recording metadata records metadata about a recording
while the recording is happening, notably it records each time a new
connection occurs.

The nested structure of the session metadata does not lend itself to the
append-only syntax of the recording meta file. In addition we do not
want to mix different kinds of metadata together. Thus the session
metadata is now written to a separate file in the BSR, and is written as
JSON which better handles the nested structure and allows for simpler
encoding/decoding.

Similarly the summary files are intended to be written to as containers
close and have been switched to JSON.
2023-05-31 12:18:23 +00:00
Timothy Messier f53d65eacd refact(sql): Rename migrations to avoid number conflicts 2023-05-31 12:18:23 +00:00
Timothy Messier b9de6cf00b fixup:(bsr): Correctly reference subcontainers when opening
This is a fixup for 60785b5a8
2023-05-31 12:18:21 +00:00
Timothy Messier 738a6c6472 feat(bsr/convert): Implement ToAsciicast
This adds support for converting a channel in a SSH BSR to an asciicast.
2023-05-31 12:18:21 +00:00
Timothy Messier 9227fcd879 feat(bsr/convert): Add logic to convert ssh channel to asciicast 2023-05-31 12:18:21 +00:00
Timothy Messier ed6882a457 feat(bsr/convert): Add asciicast package
This provides a new internal package for constructing and serializing an
asciicast in the v2 asciicast file fromat.

See: https://github.com/asciinema/asciinema/blob/develop/doc/asciicast-v2.md
2023-05-31 12:18:21 +00:00
Timothy Messier 916a919bf0 feat(bsr): Remove ascii format of protocol
This was originally introduced to ensure that the meta files only
included ascii characters. However, this makes reading the protocol from
meta file less reliable since it does not exactly match the protocol
string. Instead protocol strings will be recorded in the meta files as
is. Generally protocol strings should include readable characters.

This also updates the ssh.Protocol to be 4 readable characters.
2023-05-31 12:18:21 +00:00
Timothy Messier 4112c4e8fe feat(bsr): Add methods for opening ChunkScanners for data files 2023-05-31 12:18:21 +00:00
Timothy Messier e37fa39c95 feat(bsr/fstest): Add localfs implementation
This adds another test storage.FS implemenation. This can be used to
write/read containers and files from a local filesystem via calls to the
os pacakge.
2023-05-31 12:18:21 +00:00
Timothy Messier 713d961152 feat(bsr/fstest): Add test TempFile implementation 2023-05-31 12:18:21 +00:00
Timothy Messier b4ce802572 refact(bsr/convert): Use new storage.TempFile interface
This changes the ToAscinema function to take a storage.TempFile instead
of a storage.FS. It was noticed that when this was being used a
storage.FS was being created just prior to calling this just so that it
could then create a temporary file. It seemed to make more sense to just
pass the temporary file in, instead of needing to expand the storage.FS
interface.

This also renames this method to align with the file format that the
returned io.Reader will contain.
2023-05-31 12:18:21 +00:00
Timothy Messier e29939ce41 feat(storage): Define interface for creating temporary files
This provides a new type for a temporary file and a method on a
RecordingStorage to create temporary files. Temporary files will get
removed when closed.
2023-05-31 12:18:21 +00:00
Timothy Messier 46e1752283 feat(bsr/fstest): Support read mode
This updates the fstest implementation of a storage.FS to support
opening sub containers and files in read-only mode.

Now when calling `SubContainer`:

- If using `storage.WithCreateFile`, an error is returned if the
  container already exists.
- If not using `storage.WithCreateFile` and error is returned if the
  container does *not* exist.

When calling `OpenFile`:

- on a container that was created with `storage.ReadOnly`, an error is
  returned if attempting to open the file wth `storage.ReadWrite`.
- with `storage.WithCreateFile`, an existing file is replaced with a new
  empty file, (ie "truncated").
- without `storage.WithCreateFile`, an error is returned if the file
  does not exist.
2023-05-31 12:18:20 +00:00