Skip to content
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

Add authz to hosts endpoints #1617

Merged
merged 1 commit into from
May 25, 2024
Merged

Add authz to hosts endpoints #1617

merged 1 commit into from
May 25, 2024

Conversation

tylerwowen
Copy link
Contributor

@tylerwowen tylerwowen commented May 14, 2024

Introduced a host extractor that can map hosts to their corresponding environment. This enables host level access control.

Specifically, a host's main environment is determined by joining the tables hosts_and_agents and environs on the common field cluster.

After deploying to dev1, I discovered an issue. If a host's agent has never pinged Teletraan, there will be no record in the hosts_and_agents table. To remedy that, the group_name in the hosts table is used to join with cluster_name in the environs table.

Besides, patched the stopServiceOnHost API so that every hosts is validated before terminating.

Base automatically changed from spr/master/0e28cb39 to master May 15, 2024 17:43
@tylerwowen tylerwowen force-pushed the spr/master/ef160c01 branch 2 times, most recently from ee4f20a to 3dead2a Compare May 15, 2024 22:11
@tylerwowen tylerwowen changed the title Introduce host extractor Add authz to hosts endpoints May 15, 2024
@tylerwowen
Copy link
Contributor Author

Previous description for record

Introduced a host extractor that can map hosts to their corresponding environment.
This allows service owners to restart sidecars deployed on their hosts.

Specifically, a host's main environment is determined by joining the tables hosts_and_agents and environs on the common field cluster.

Access matrix

The following tables illustrate both the resource based and environment based access for different users.

Resource based

This is the proposed change in this PR.

Access of the mainEnv user

mainEnv xEnv envoy pastis
mainEnv-host1 T T T T
mainEnv-host2 T T T T
xEnv-host1 F F F F

Access of the xEnv user

mainEnv xEnv envoy pastis
mainEnv-host1 F F F F
mainEnv-host2 F F F F
xEnv-host1 T T T T

Access of the envoy sidecar user

The envoy sidecar user cannot reset an individual environment, but the user can invoke reset_failed_agents from the sidecar environment to reset all failed agent.

mainEnv xEnv envoy pastis
mainEnv-host1 F F conditional T F
mainEnv-host2 F F conditional T F
xEnv-host1 F F conditional T F

Environment based

Current implementation without this PR.

Access of the mainEnv user

mainEnv xEnv envoy pastis
mainEnv-host1 T F F F
mainEnv-host2 T F F F
xEnv-host1 T F F F

Access of the xEnv user

mainEnv xEnv envoy pastis
mainEnv-host1 F T F F
mainEnv-host2 F T F F
xEnv-host1 F T F F

Access of the envoy sidecar user

mainEnv xEnv envoy pastis
mainEnv-host1 F F T F
mainEnv-host2 F F T F
xEnv-host1 F F T F

@tylerwowen tylerwowen requested a review from osoriano May 16, 2024 16:28
osoriano
osoriano previously approved these changes May 16, 2024
commit-id:ef160c01
@tylerwowen
Copy link
Contributor Author

After deploying to dev1, I discovered an issue. If a host's agent has never pinged Teletraan, there will be no record in the hosts_and_agents table. To remedy that, the group_name in the hosts table is used to join with cluster_name in the environs table.

Besides, patched the stopServiceOnHost API so that every hosts is validated before terminating.

@osoriano can you please review again? Thanks.

@tylerwowen tylerwowen requested a review from osoriano May 23, 2024 23:54
" FROM hosts_and_agents ha " +
" JOIN environs e ON ha.auto_scaling_group = e.cluster_name " +
" WHERE ha.host_id = ? )" +
"ORDER BY h.create_date ASC LIMIT 1)";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a LIMIT 1 on the outer query as well? or do extra rows just get ignored so it does not matter?

Also, I'm thinking the subquery could be removed if we had an outer LIMIT 1 and the first select was ordered before the second select. Might not make much difference.

LGTM overall

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The NOT EXISTS clause that checks whether the first query returns any results. If the first query returns results, the NOT EXISTS clause will be false, and the second query will not return any results. If the first query does not return any results, the NOT EXISTS clause will be true, and the second query will return its results.

We use BeanHandler so it will take the first result. Although we don't have unique key constraint on the cluster_name column, we don't have meaningful duplications

 select  cluster_name from environs GROUP BY cluster_name having count(*) > 1;
+--------------+
| cluster_name |
+--------------+
| NULL         |
|              |
+--------------+
2 rows in set (0.00 sec)

@tylerwowen tylerwowen merged commit d463e65 into master May 25, 2024
9 checks passed
@tylerwowen tylerwowen deleted the spr/master/ef160c01 branch May 25, 2024 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy-service Includes changes to deploy-service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants