-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support alternate password for PTF container (#16457)
Manually cherry-pick #16457 to 202311 branch due to conflicts. What is the motivation for this PR? The PTF container is always using default password. If the PTF container is on same bridge with the host server's management IP, then it is easily accessible from other host servers. This is not secure enough. We need to support alternate password for the PTF container and password rotation. How did you do it? This change improved the ansible related code to support accessing the PTF containers using the multi_ssh_pass ansible plugin. Then we can specify alternate passwords for the PTF container. When alternate passwords are specified, the default password of PTF container is updated after PTF creation. How did you verify/test it? Tested remove-topo/add-topo/restart-ptf on KVM and physical testbed. Signed-off-by: Xin Wang <xiwang5@microsoft.com>
- Loading branch information
Showing
11 changed files
with
157 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ansible_connection: multi_passwd_ssh | ||
|
||
ansible_user: root | ||
ansible_ssh_pass: root | ||
# ansible_altpasswords: | ||
# - fakepassword1 | ||
# - fakepassword2 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,43 @@ | ||
--- | ||
- name: Include variables for PTF containers | ||
include_vars: | ||
dir: "{{ playbook_dir }}/group_vars/ptf_host/" | ||
- name: Set ptf host | ||
set_fact: | ||
ptf_host: "{{ ptf_ip.split('/')[0] }}" | ||
|
||
- name: Add ptf host | ||
add_host: | ||
name: "{{ ptf_host }}" | ||
groups: | ||
- ptf | ||
|
||
- name: Check if ptf_tgen exists | ||
supervisorctl: | ||
name: ptf_tgen | ||
state: present | ||
become: True | ||
delegate_to: "{{ ptf_host }}" | ||
ignore_errors: True | ||
register: ptf_tgen_state | ||
|
||
- block: | ||
- name: Set ptf host | ||
set_fact: | ||
ptf_host: "ptf_{{ vm_set_name }}" | ||
ptf_host_ip: "{{ ptf_ip.split('/')[0] }}" | ||
- name: Copy scapy scripts to ptf host | ||
copy: | ||
src: "{{ item }}" | ||
dest: "/ptf_tgen/" | ||
with_fileglob: | ||
- "{{ playbook_dir }}/../spytest/spytest/tgen/scapy/*" | ||
- "{{ playbook_dir }}/../spytest/spytest/dicts.py" | ||
|
||
- name: Add ptf host | ||
add_host: | ||
hostname: "{{ ptf_host }}" | ||
ansible_user: "{{ ptf_host_user }}" | ||
ansible_ssh_host: "{{ ptf_host_ip }}" | ||
ansible_ssh_pass: "{{ ptf_host_pass }}" | ||
groups: | ||
- ptf_host | ||
- name: Create ptf_tgen service | ||
copy: | ||
src: "/ptf_tgen/service.sh" | ||
dest: "/ptf_tgen/ptf_tgen.sh" | ||
mode: "0755" | ||
remote_src: yes | ||
|
||
- name: Check if ptf_tgen exists | ||
- name: Start ptf_tgen | ||
supervisorctl: | ||
name: ptf_tgen | ||
state: present | ||
become: True | ||
delegate_to: "{{ ptf_host }}" | ||
ignore_errors: True | ||
register: ptf_tgen_state | ||
|
||
- block: | ||
- name: Copy scapy scripts to ptf host | ||
copy: | ||
src: "{{ item }}" | ||
dest: "/ptf_tgen/" | ||
with_fileglob: | ||
- "{{ playbook_dir }}/../spytest/spytest/tgen/scapy/*" | ||
- "{{ playbook_dir }}/../spytest/spytest/dicts.py" | ||
|
||
- name: Create ptf_tgen service | ||
copy: | ||
src: "/ptf_tgen/service.sh" | ||
dest: "/ptf_tgen/ptf_tgen.sh" | ||
mode: "0755" | ||
remote_src: yes | ||
|
||
- name: Start ptf_tgen | ||
supervisorctl: | ||
name: ptf_tgen | ||
state: restarted | ||
become: True | ||
delegate_to: "{{ ptf_host }}" | ||
when: ptf_tgen_state is not failed | ||
when: | ||
- ptf_host_user is defined | ||
- ptf_host_pass is defined | ||
state: restarted | ||
become: True | ||
delegate_to: "{{ ptf_host }}" | ||
when: ptf_tgen_state is not failed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
- include_vars: | ||
file: "{{ playbook_dir }}/group_vars/ptf/secrets.yml" | ||
name: raw_ptf_secrets | ||
no_log: true | ||
|
||
- name: Render ptf secrets | ||
set_fact: | ||
ptf_secrets: >- | ||
{{ | ||
dict( | ||
raw_ptf_secrets.keys() | zip(raw_ptf_secrets.values() | ||
) | ||
) | ||
}} | ||
no_log: true | ||
|
||
- block: | ||
|
||
- name: Init default ptf_username | ||
set_fact: | ||
ptf_username: "root" | ||
when: ptf_username is not defined | ||
|
||
- name: Init default ptf_password | ||
set_fact: | ||
ptf_password: "root" | ||
when: ptf_password is not defined | ||
no_log: true | ||
|
||
- name: Override default ptf_username | ||
set_fact: | ||
ptf_username: "{{ ptf_secrets['ansible_user'] }}" | ||
when: "'ansible_user' in ptf_secrets" | ||
|
||
- name: Override default ptf_password | ||
set_fact: | ||
ptf_password: "{{ ptf_secrets['ansible_ssh_pass'] }}" | ||
when: "'ansible_ssh_pass' in ptf_secrets" | ||
|
||
- name: Get ptf_alt_passwords from ptf_secrets | ||
set_fact: | ||
ptf_alt_passwords: "{{ ptf_secrets['ansible_altpasswords'] }}" | ||
no_log: true | ||
|
||
- name: If ptf_alt_passwords is a list, set ptf_password to its first value | ||
set_fact: | ||
ptf_password: "{{ ptf_alt_passwords[0] }}" | ||
when: ptf_alt_passwords | type_debug == "list" and ptf_alt_passwords | length > 0 | ||
no_log: true | ||
|
||
- name: If ptf_alt_passwords is not a list, log a debug message | ||
debug: | ||
msg: >- | ||
The 'ansible_altpasswords' field in group_vars/ptf/secrets.yml is not a list. | ||
Falling back to use the 'ansible_ssh_pass' field." | ||
when: ptf_alt_passwords | type_debug != "list" | ||
|
||
- name: Update ptf username and password | ||
command: docker exec -t ptf_{{ vm_set_name }} sh -c 'echo "{{ ptf_username }}:{{ ptf_password }}" | chpasswd' | ||
become: yes | ||
no_log: true | ||
|
||
when: ptf_secrets is defined and 'ansible_altpasswords' in ptf_secrets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters