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

AWS Code Build fails with error message #303

Closed
ckunki opened this issue Jul 15, 2024 · 12 comments · Fixed by #305
Closed

AWS Code Build fails with error message #303

ckunki opened this issue Jul 15, 2024 · 12 comments · Fixed by #305
Assignees
Labels
bug Unwanted / harmful behavior

Comments

@ckunki
Copy link
Contributor

ckunki commented Jul 15, 2024

AWS CodeBuild Log

In setup of test_jupyter_with_ec2_based_on_new_ami

    @pytest.fixture(scope="session")
    def new_ec2_from_ami():

Line 97

change_password(host=ec2_instance_description.public_dns_name, user='ubuntu',
                                curr_pass=default_password, new_password=new_password)

Error message

/root/.cache/pypoetry/virtualenvs/exasol-ai-lab-X0J5PNhP-py3.10/lib/python3.10/site-packages/
paramiko/auth_handler.py:263: BadAuthenticationType

@ckunki ckunki added the bug Unwanted / harmful behavior label Jul 15, 2024
@ckunki
Copy link
Contributor Author

ckunki commented Jul 17, 2024

Currently, the AI-Lab code uses lock_passwd from module users-and-groups, potentially, module set-passwords could also play a role.

AI Lab already contains Ansible task Enable SSH password authentication in file reset_password_tasks.yml, but the current assumption is that later this is disabled by cloud init, again.

Observation: Inside the Docker Container the file /etc/ssh/sshd_config doesn't exist anymore.

@ckunki
Copy link
Contributor Author

ckunki commented Jul 17, 2024

Proposal:

- name: Enable SSH password authentication
  become: "{{need_sudo}}"
  lineinfile:
    dest: /etc/cloud/cloud.cfg
    regexp: '^(\s*)ssh_pwauth: false'
    line: '\1ssh_pwauth: true'
    state: present
    backrefs: yes

@ckunki
Copy link
Contributor Author

ckunki commented Jul 17, 2024

Proposal for investigation:

  • Start EC2 instance via ai-lab CLI and run Ansible
    • setup-ec2-and-install-dependencies
    • or install-dependencies on existing
  • inspect (e.g. via temporary ssh key generated by ai-lab)
    • /etc/ssh/sshd_config
    • /etc/cloud/cloud.cfg
  • export AMI, CLI export-vm
  • launch EC2 from AMI
  • inspect per SSH key, Note: This requires to put my ssh key to AWS, "Key pairs"

@ckunki ckunki self-assigned this Jul 17, 2024
@ckunki
Copy link
Contributor Author

ckunki commented Jul 17, 2024

It seems already Ansible installation reports an error:

/usr/bin/apt-get -y
  -o "Dpkg::Options::=--force-confdef"
  -o "Dpkg::Options::=--force-confold"
  install 'network-manager=1.36.4-2ubuntu1'
  -o APT::Install-Recommends=no'

failed: E: Unable to correct problems, you have held broken packages.
stdout:

Reading package lists...
Building dependency tree...
Reading state information...

Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: network-manager : Depends: libnm0 (= 1.36.4-2ubuntu1) but 1.36.6-0ubuntu2 is to be installed

@ckunki
Copy link
Contributor Author

ckunki commented Jul 17, 2024

I will update network-manager as described above

@ckunki
Copy link
Contributor Author

ckunki commented Jul 17, 2024

I could retrieve files /etc/cloud/cloud.cfg and /etc/ssh/sshd_config now.

/etc/cloud/cloud.cfg contains

system_info:
  default_user:
    name: ubuntu
    lock_passwd: True

/etc/ssh/sshd_config contains

#PasswordAuthentication yes

@ckunki
Copy link
Contributor Author

ckunki commented Jul 17, 2024

Calling poetry run python exasol/ds/sandbox/main.py reset-password now displays

Unable to encrypt nor hash, passlib must be installed. No module named 'passlib'. Unable to encrypt nor hash, passlib must be installed. No module named 'passlib'"

See https://stackoverflow.com/questions/78525098/ansible-unable-to-encrypt-nor-hash-passlib-must-be-installed

@ckunki
Copy link
Contributor Author

ckunki commented Jul 17, 2024

Added dependency to passlib: poetry add passlib, unfortunatly caused some downgrades of other dependencies:

  • Downgrading urllib3 (2.2.2 -> 2.2.1)
  • Downgrading botocore (1.34.137 -> 1.34.125)
  • Installing commonmark (0.9.1)
  • Downgrading fastjsonschema (2.20.0 -> 2.19.1)
  • Downgrading plux (1.11.0 -> 1.10.0)
  • Downgrading psutil (6.0.0 -> 5.9.8)
  • Downgrading pydantic-core (2.20.0 -> 2.18.4)
  • Downgrading rich (13.7.1 -> 12.6.0)
  • Downgrading s3transfer (0.10.2 -> 0.10.1)
  • Downgrading boto3 (1.34.137 -> 1.34.125)
  • Installing jsonpickle (3.2.1)
  • Installing pbr (6.0.0)
  • Downgrading pydantic (2.8.0 -> 2.7.4)
  • Downgrading setuptools (70.2.0 -> 70.0.0)
  • Downgrading ansible-core (2.17.1 -> 2.16.7)
  • Downgrading invoke (2.2.0 -> 1.7.3)
  • Installing jschema-to-python (1.2.3)
  • Installing junit-xml (1.9)
  • Downgrading networkx (3.3 -> 2.8.8)
  • Installing pathlib2 (2.3.7.post1)
  • Downgrading pytest (8.2.2 -> 7.4.4)
  • Installing sarif-om (1.0.4)
  • Downgrading ansible (10.1.0 -> 9.6.1)
  • Downgrading cfn-lint (1.4.2 -> 0.65.1)
  • Downgrading fabric (3.2.2 -> 2.7.1)
  • Downgrading importlib-metadata (7.2.1 -> 7.1.0)
  • Installing passlib (1.7.4)
  • Downgrading pytest-check-links (0.10.1 -> 0.9.3)
  • Downgrading tenacity (8.4.2 -> 8.3.0)

ckunki added a commit that referenced this issue Jul 17, 2024
@ckunki
Copy link
Contributor Author

ckunki commented Jul 17, 2024

I was now able to run poetry run python exasol/ds/sandbox/main.py reset-password without obvious errors.

After commenting out some parts of file reset_password_tasks.yml, I was still able to log in via ssh key file but not with password.

File contents:

$ grep -H lock /etc/cloud/cloud.cfg ; grep -H Passwo /etc/ssh/sshd_config
/etc/cloud/cloud.cfg:    lock_passwd: False
/etc/ssh/sshd_config:PasswordAuthentication yes

@ckunki
Copy link
Contributor Author

ckunki commented Jul 17, 2024

Thanks to @tkilias we identified to additionally need sshd option KbdInteractiveAuthentication yes.
Additionally, we were able to remove dependency passlib and replace it by python standard module crypt.
This enables to revert the downgrades of the other packages mentioned above.

@ckunki
Copy link
Contributor Author

ckunki commented Jul 18, 2024

Python test based on fabric / paramiko still failed as with

paramiko.ssh_exception.BadAuthenticationType:
Bad authentication type; allowed types: ['publickey', 'keyboard-interactive']

It could be possible to use keyboard-interactive authentication with fabric, see

On the other hand, I found the following at https://superuser.com/a/1828947, which turned out to be true in our case, too:

sneaky file /etc/ssh/sshd_config.d/60-cloudimg-settings.conf that had a single line PasswordAuthentication no

So I updated ansible task to modify all files in folder /etc/ssh/sshd_config.d, too,
using file globbing for remote files, as described here: https://stackoverflow.com/questions/33543551/

@ckunki
Copy link
Contributor Author

ckunki commented Jul 18, 2024

I manually verified login with KbdInteractiveAuthentication no in /etc/ssh/sshd_config to be successful.

ckunki added a commit that referenced this issue Jul 19, 2024
* #303: Fixed AWS Codebuild
* Used Python standard package crypt and forwarded hashed password to ansible.
* FIxed PasswordAuthentication in additional config files, too
* Fixed review findings.
* Added comment regarding ssh password authentication vs. keyboard-interactive
* Replaced shell ls by ansible.builtin.find
* Disabled sagemaker notebook tests

[CodeBuild]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unwanted / harmful behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants