Commit Graph
4374 Commits
Author SHA1 Message Date
Hugo ec2d5d4285 feat(host/plugin): Support empty host catalog secrets 2024-09-30 21:24:18 +01:00
Hugo a5237cc171 feat(host/plugin): Use plugin client pkg func on job_set_sync 2024-09-30 21:24:18 +01:00
Hugo 5b5aa484da feat(host/plugin): Extract plugin client functionality to pkg func 2024-09-30 21:24:18 +01:00
Hugo ee9f9fb4a1 feat(worker): Support running AWS host plugin 2024-09-30 21:24:18 +01:00
Hugo 60dc0ec3ff feat(host/plugin): Always send plugin information on DHC requests 2024-09-30 21:24:18 +01:00
Hugo c3d03f69d8 feat(cmd): Support plugin host catalog worker filter 2024-09-30 21:24:18 +01:00
Hugo b8046a3ef3 feat(handlers/host_catalogs): Support plugin host catalog worker filter 2024-09-30 21:24:18 +01:00
Hugo 7449fd6f2a feat(host/plugin): Implement worker filter 2024-09-30 21:24:18 +01:00
Hugo 22b54c8b97 fix(event): Prevent eventer data races by removing shallow object copy (#5139)
This issue was surfaced through other changes (PR 5137).

Given that the eventer works in a singleton pattern (see sysEventer
global variable), performing this shallow object copy can cause a data
race because the copy operation reads the underlying eventer data
structures. At the same time, given the global nature of this eventer,
other goroutines can be writing to those same data structures.

Since we're already using a singleton pattern in this package, and given
that the current copy operation is shallow, copying the object doesn't
seem necessary, so this commit changes `StandardWriter` to build the
`logAdapter` with the `e` eventer directly instead of copying it.
2024-09-30 12:17:56 -07:00
Ryan Derr de141e34a9 Worker Connection Failure Add Controller Target (#5109)
* ICU-11692 Add Upstream Controller Addrs When Throwing Controller Connection Failure

* Reference Consistant Load Variable For Client Connection
2024-09-30 11:51:55 -07:00
Timothy Messier 37bf59243a refact(session): Replace state start_time/end_time with time range (#5134)
This replaces the start_time, end_time, and previous_end_time columns on
the session_state table with a time range column that records when the
state was active. This allowed for dropping several constraints on the
session_state table that were used to ensure that states for a session
did not overlap. Instead this can be ensured with a single exclusion
constraint. By reducing the number of constraints, it improves the
performance for a number of queries involved with session state. Most
notably when resolving delete cascades of resources related to sessions,
such as targets, where as part of the delete transaction large numbers
of sessions get canceled. Similarly, when sessions get deleted, and the
corresponding session_state rows are deleted, these constraints all must
be checked during the transaction.

The domain layer continues to expose StartTime and EndTime fields on
session.State. However it drops PreviousEndTime, which was never used by
anything calling the domain layer.

See:
    https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-EXCLUSION
    https://www.postgresql.org/docs/current/rangetypes.html
2024-09-30 14:39:19 -04:00
Timothy Messier f6bdbd116e changelog: Add details for cache speedup and performance improvements (#5130)
Refs: f431d1e223
Refs: d5817f0adab7f5c1f045fa4a5c15a6dc553b022c
2024-09-30 13:33:22 -04:00
Jeff Mitchell dc74e725d4 Some clarity updates to comments in ACL code (#5136) 2024-09-27 12:24:33 -04:00
Irena RindosandMichael Li 7d3fbf3797 chore: update changelog for 0.17.2 (#5131)
* chore: update changelog for 0.17.2

Co-authored-by: Michael Li <michael.li@hashicorp.com>
2024-09-25 14:21:37 -04:00
Irena Rindos 37d8330a10 update changelog with controllers deprecation version (#5129) 2024-09-25 09:38:20 -04:00
Timothy Messier f431d1e223 Merge pull request #5128 from hashicorp/tmessi-cherry-pick-cache-speedup
Cache speed up and additional performance improvements

This includes several changes to improve the performance of the
client cache, including:

* Making the sqlite database for the cache persistent, so the cache does
   not need to be rebuilt each time the boundary client is started.
* Limiting the number of results retrieved when listing resources to 250.
* Preventing redundant refreshes running at the same time for a given
   client.
* Adding indexes to the cache database.

It also refactors the grants query that is run to fetch grants for a
user when processing a controller API request. This greatly reduces the
amount of data that is returned from the database, but required a number
of changes in the application logic to account for different kinds of
grant scopes.

Lastly this makes some performance improvements in the controller
database. It adds several indexes to help with the grants query and with
delete cascades for several resources. And it changes the delete trigger
for sessions to run per statement instead of per row to help with bulk
deleting of sessions.
2024-09-24 14:16:33 -04:00
Timothy Messier 632d048f7b lint: Fix linter errors
(cherry picked from commit 51a2b2035f9c6bb51fe8f5f1defeeb514183fecd)
2024-09-24 14:18:54 +00:00
Timothy Messier a92c88dfb5 refact(db): Replace get_deleted_tables function with a view
This function was returning the set of deletion tables. A view seems
better suited for this task since it would allow for applying additional
filters of the result set. This was particularly necessary to easily
make changes to some sqltests due to switching the delete trigger for
the session table.

(cherry picked from commit 32d41639892950b21fafc39b50c10b997c6d5121)
2024-09-24 14:18:54 +00:00
Timothy Messier 33037b4887 perf(db): Use statement trigger for marking deleted sessions
When sessions are deleted, a trigger is used to insert records into the
session_deleted table. This table is utilized by the sessions list
endpoint when using a refresh token to inform a client of the sessions
that have been deleted since the last request. We delete sessions in
bulk via a controller job to delete sessions that have been terminated
over an hour ago, which results in the trigger running a large number of
separate insert statements while processing the delete statement.

This changes the trigger to run once for the delete statement, instead
of for each row, resulting in a single bulk insert statement to the
session_deleted table.

This new trigger function also avoids the use of `on conflict`. When
testing this function, while the single statement was still faster than
running multiple inserts, the `on conflict` still added significant
overhead, even when there were no conflicts. It should be safe to
perform the insert without the `on conflict`, since the same ID should
never be deleted more than once if it is successfully deleted.

(cherry picked from commit 3569b36c6eb2bee7a4e36e7584fcc6bbf1124f95)
2024-09-24 14:18:54 +00:00
Timothy Messier 091ed6bacb perf(db): Reorder index columns for primary keys
When processing a controller API request, system uses a query to fetch
the grants for the requesting user. This query requires pulling together
information from several tables, and is currently performing many
sequential scans to do so. For a number of the tables involved, there
are indexes from multi-column primary keys, however, due to the order of
the columns in the index, the postgres planner would need to do a full
scan of the index, which can be less efficient than a sequential scan,
so instead it will perform a sequential scan of the table.

This recreates the primary keys while swapping the order of the columns
in the primary key definition, and thus the order in the index. By doing
so, the planner will not need to perform a full index scan, and will be
more likely to use the index when executing the grants query.

(cherry picked from commit 5577b3c358e9d45cd7ec02fc951e45d52e50595e)
2024-09-24 14:18:54 +00:00
Timothy Messier c9578b441a perf(db): Add indexes on foreign key to improve delete performance
This adds indexes for a few categories:

1. Foreign keys on the session table. These are set to `null` when the
   referenced row is deleted. These indexes will help to more
   efficiently set these `null` values in the case where a target is
   deleted, or and auth token is deleted.
2. Foreign keys from other tables to the session table. These are either
   set to `null` or cascade deleted when a session is deleted. These
   indexes help with these update/deletes when a session is deleted.
3. A multi-column index on session_state. This helps with the query that
   is used to delete all terminated sessions that have been terminated
   for over an hour.

(cherry picked from commit 263a96e9ddd197cb36f2c4c74e91ac034112321e)
2024-09-24 14:18:54 +00:00
Jeff Mitchell 62d4f8453b Don't explode grants from the DB (#5104)
This removes the Cartesian product in the DB for GrantsForUser in favor
of returning the actual grant scope information and dealing with it in
application code.

(cherry picked from commit 913cd536823d73994acc4f4d833208c1cc05f91b)
2024-09-24 14:18:53 +00:00
Irena Rindos 2945692bf4 Client cache API paging (#5107)
* internal/clientcache: add -force-reset-schema flag

* clientcache: stream list pages directly to DB

---------

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
(cherry picked from commit ccea8a4ce53f7b0d1105c1c1e4875e443635d96a)
2024-09-24 14:18:53 +00:00
Jeff Mitchell 3a4ee032d9 Paginate targets in cache (#5101)
* Update Go API to support pagination
* Implement pagination of targets in cache

(cherry picked from commit cd25fad42f325fc050b7ea3bec3336780d2b5e16)
2024-09-24 14:18:53 +00:00
Jim 2a87dcad48 fix (cache/db): add indexes for desktop queries (#5091)
(cherry picked from commit bfdbae1f042c4eb1b05e0373e1aaf2db55c9bb3b)
2024-09-24 14:18:53 +00:00
Jim 85afd56266 fix (cache): support for DB debug logging (#5087)
(cherry picked from commit a7fe48b8d827d1bf68ff8eea205428dd5faae381)
2024-09-24 14:18:53 +00:00
Jim 863359aa26 test (cache/search): fix NewTestServer(...) storage (#5081)
Fix ensures that the TestServer returned uses the
correct directory for writing its sqlite files,
which was created via t.TempDir()

(cherry picked from commit 85f91043a164bdacc1c6738ae0e7c50077d55c79)
2024-09-24 14:18:53 +00:00
Jeff Mitchell 829ea02e6f Ensure only one refresh is running for a user/resource at a time (#5054)
This ensures we don't have competing update processes running. When doing the
inline RefreshForSearch, a specific error will be returned so we can hint in
the API that we're in the middle of a refresh.

(cherry picked from commit 54776091e32af2f2f110f2bf10d0617bd5677aba)
2024-09-24 14:18:53 +00:00
Jeff Mitchell b04de5ac4b Add implicit-scopes resource type to cache (#5053)
This allows getting a list of scope IDs known by the cache via cached
targets and sessions. It is not refreshed from the controller. The name
contains `implicit` in case we ever want e.g. `scopes`.

(cherry picked from commit c0a318c58367d8ec55365447f41cf007eab64ce3)
2024-09-24 14:18:53 +00:00
Jim 4d8a7dd39a feat (clientcache): use a persistent cache (#5051)
By default, we will use a persistent cache for the
client cache. This will allow us to keep the cache
across restarts of the server and it will also
reduce the amount of time it takes to start the
server while reducing the amount of memory used.

This change also includes a validation of the cache
schema version. If the schema version is different
from the one expected, the cache will be
reset/recreated.

(cherry picked from commit cf8a51f3834033b7f986a9a7e091ab31c4328415)
2024-09-24 14:18:53 +00:00
Jeff Mitchell 384fc332be Restrict cache results to 250 entries by default (#5049)
A query parameter `max_result_set_size` can be specified to set a
per-request limit, with `-1` meaning all values. If there were more
entries than the max size used for the request, an `incomplete` boolean
is set in the response.

(cherry picked from commit 3cdd07889be5e4e6f21d044cb60fad1face4be08)
2024-09-24 14:18:53 +00:00
Michael Li 30145b1f9c chore: Update use of deprecated hub command (#5127) 2024-09-23 14:37:22 -04:00
Johan Brandhorst-Satzkorn 0ef88d0f05 Add semgrep rules (#5042)
* Add semgrep rules

Instrument our security scanner with the ability to use custom semgrep
rules. This is inspired by the HVS teams use of semgrep.

* semgrep: add rule to detect string interpolation in WithInfoMsg

The event.WithInfoMsg function expects a set of key value tuples,
but it can easily be misunderstood to accept string interpolation
arguments. This check will error if any string interpolation verbs are
used in calls to event.WithInfoMsg
2024-09-23 10:07:57 -07:00
Irena Rindos 35679c6a5b chore(config): remove deprecated controllers field (#5125)
* chore(config): remove deprecated controllers field
2024-09-23 11:45:34 -04:00
Damian Debkowski 79bf12bd23 fix(cmd): resolve make gen issue (#5124) 2024-09-20 13:29:26 -07:00
Michael Li 40efebf7ab test(e2e): Add check for target authorize-session using scope name and target name (#5118) 2024-09-20 15:28:05 -04:00
Damian Debkowski 29efd5e6c6 test: ensure ipv6 compatability (#5110) 2024-09-20 11:30:27 -07:00
Irena Rindos eb33649ded (clientagentcmd): plumb thru env var (#5123)
* (clientagentcmd): plumb thru env var
2024-09-20 12:33:48 -04:00
Timothy Messier fe129b4268 fix(metrics): Fix matching logic for authorize session endpoint (#5121)
The target authorize session endpoint allows for alternative target
identifiers besides the public id. For this to function correctly, the
grpc gateway path definition for the endpoint deviates from the common
pattern used for other endpoints that include ids. When this change was
done, it was not accounted for in the logic used to capture the
prometheus metrics for api requests to this particular endpoint,
resulting in the metrics never incrementing for the authorize session
endpoint.

This fix updates the matching logic used for the metrics to ensure that
the metrics are incremented for this endpoint.

See: c149bc4a79
2024-09-19 14:02:41 -04:00
dani 1b24cab932 update bsr tests to use ::1 (#5120) 2024-09-19 12:30:10 -04:00
Damian Debkowski 9576ed40dc test: improve test to ensure ipv6 compatability (#5113) 2024-09-19 08:55:27 -07:00
David Bond 61c1544446 Fix panic in credential renewal job (#5116)
This commit modifies the credential renewal job to handle a case where the `renewLease` method can
return `nil, nil`. Currently, a panic is caused by usage of the `renewedCred` variable in this scenario.

This commit adds a nil check and returns an error if the `renewedCred` variable is returned as `nil`.

Signed-off-by: David Bond <davidsbond93@gmail.com>
2024-09-18 17:46:12 +01:00
Jeff Mitchell b120a03f43 Fix tests (#5114) 2024-09-18 11:09:15 -04:00
Ryan Derr 913e6d755f ICU-11661 Add scope name in options slice for authorized-sessions (#5108) 2024-09-13 15:09:38 -05:00
Damian Debkowski 390fca3306 test(server): validate ipv6 address for upsert worker status (#5079) 2024-09-11 13:02:19 -07:00
Damian Debkowski 26a07c1418 fix(sbc): ensure secrets cannot be empty & add unit tests (#5102) 2024-09-11 13:01:45 -07:00
Johan Brandhorst-Satzkorn 41de35f2b1 internal/daemon/controller+worker: propagate downstream timeout (#5083)
Propagate the downstream worker timeout into the
downstream receiver and downstream ticker
so we have a configurable consistent timeout
value to use for worker to worker interactions.

Also change the atomic.Pointer to an atomic.Int64
for consistency with other values.
2024-09-11 12:19:11 -04:00
Irena Rindos 83b61275d5 (cmd): unhide client agent commands (#5097) 2024-09-11 11:20:18 -04:00
15d440a90d docs: Clarify credential workflow for SSH target types (#5082)
* docs: Clarify credential workflow for SSH target types

* adds clarifier about brokered creds on SSH targets

* Update website/content/docs/configuration/credential-management/configure-credential-injection.mdx

Co-authored-by: Robin Beck <stellarsquall@users.noreply.github.com>

---------

Co-authored-by: stellarsquall <stellarsquall@protonmail.ch>
Co-authored-by: Robin Beck <stellarsquall@users.noreply.github.com>
2024-09-11 11:10:59 -04:00
Irena Rindos 0bf038b001 update changelog to docoument gRPC update (#5094) 2024-09-09 14:59:11 -04:00