Skip to content

Commit 275d52d

Browse files
authored
Move listing cross account keys to teardown playbook (#147)
* Isolate listing cross-account keys to the teardown phase due to potentially restricted privileges Signed-off-by: Jesus Perez Rey <[email protected]>
1 parent c43b1c7 commit 275d52d

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

roles/platform/tasks/initialize_gcp.yml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,3 @@
5252
loop: "{{ __gcp_subnets_discovered.resources }}"
5353
loop_control:
5454
loop_var: __gcp_subnet_item
55-
56-
- name: Discover GCP Cross Account Service Account Keys
57-
register: __gcp_xaccount_sa_discovered
58-
failed_when:
59-
- __gcp_xaccount_sa_discovered.rc == 1
60-
- "'NOT_FOUND:' not in __gcp_xaccount_sa_discovered.stderr"
61-
- "'Permission iam.serviceAccountKeys.list' not in __gcp_xaccount_sa_discovered.stderr"
62-
command: >
63-
gcloud iam service-accounts keys list
64-
--iam-account "{{ plat__gcp_xaccount_identity_name }}@{{ plat__gcp_project }}.iam.gserviceaccount.com"
65-
--format="json"
66-
67-
- name: Set discovered Cross Account Service Account keys if exists
68-
when:
69-
- __gcp_xaccount_sa_discovered is defined
70-
- __gcp_xaccount_sa_discovered.stdout is defined
71-
- __gcp_xaccount_sa_discovered.stdout | length > 0
72-
ansible.builtin.set_fact:
73-
plat__gcp_xaccount_keys: "{{ __gcp_xaccount_sa_discovered.stdout | from_json }}"

roles/platform/tasks/initialize_teardown_gcp.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,23 @@
1212
# distributed under the License is distributed on an "AS IS" BASIS,
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
15-
# limitations under the License.
15+
# limitations under the License.
16+
17+
- name: Discover GCP Cross Account Service Account Keys
18+
register: __gcp_xaccount_sa_discovered
19+
failed_when:
20+
- __gcp_xaccount_sa_discovered.rc == 1
21+
- "'NOT_FOUND:' not in __gcp_xaccount_sa_discovered.stderr"
22+
- "'Permission iam.serviceAccountKeys.list' not in __gcp_xaccount_sa_discovered.stderr"
23+
command: >
24+
gcloud iam service-accounts keys list
25+
--iam-account "{{ plat__gcp_xaccount_identity_name }}@{{ plat__gcp_project }}.iam.gserviceaccount.com"
26+
--format="json"
27+
28+
- name: Set discovered Cross Account Service Account keys if exists
29+
when:
30+
- __gcp_xaccount_sa_discovered is defined
31+
- __gcp_xaccount_sa_discovered.stdout is defined
32+
- __gcp_xaccount_sa_discovered.stdout | length > 0
33+
ansible.builtin.set_fact:
34+
plat__gcp_xaccount_keys: "{{ __gcp_xaccount_sa_discovered.stdout | from_json }}"

0 commit comments

Comments
 (0)