Skip to content
  1. Nov 21, 2023
    • anarcat's avatar
      d4a5053d
    • anarcat's avatar
      workaround SSH host key lookup bug in paramiko · 6233f8e4
      anarcat authored
      We found that the order of keys in the known_hosts generated by
      ud-ldap is non-deterministic and will sometimes put the (initramfs)
      key first. This normally wouldn't be a problem: SSH considers all
      keys when doing lookups and will accept any valid one specified in the
      file.
      
      But paramiko only takes the *first* key, which means that if the
      "(initramfs)" key ends up first in the file, paramiko will fail to
      connect most of the time.
      
      Now, this fixes the common case by putting the initramfs key second,
      but of course this will still fail if paramiko tries to connect while
      the host is in its initramfs.
      6233f8e4
  2. Oct 12, 2023
    • anarcat's avatar
      Merge branch 'py3_allowed_hosts_unicode-0.3.104' · 0be7fcab
      anarcat authored
      0be7fcab
    • anarcat's avatar
      LDAP now returns bytes, fix another comparison in ud-mailgate · 88bb60d2
      anarcat authored
      We seem to be playing whack-a-mole here, maybe a better fix would be
      to fix the LDAP connection to properly decode bytes for all calls, but
      for now let's just fix this one issue, hopefully.
      
      This was tested by manually reproducing part of the code in
      production, with:
      
          import ldap
          lc = ldap.initialize('ldap://db.torproject.org')
          lc.simple_bind_s("", "")
          HostBaseDn = "ou=hosts,dc=torproject,dc=org"
          Res = lc.search_s(HostBaseDn, ldap.SCOPE_SUBTREE, '(objectClass=debianServer)', ['hostname'])
          ValidHostNames = []
          for _, value in Res:
              for s in value.get("hostname", []):
                  ValidHostNames.append(s.decode('utf-8'))
          'perdulce.torproject.org' in ValidHostNames
      
      It would be pretty neat to have a mockup for the LDAP server that
      would allow us to unit-test this, but for now we're just scratching
      this painful itch, again.
      
      Closes: team#41357
      88bb60d2
  3. Sep 28, 2023
  4. Sep 27, 2023
  5. Sep 22, 2023
  6. Sep 18, 2023
  7. Sep 14, 2023
    • anarcat's avatar
      Merge branch 'install-restore-crash-0.3.104' · a5caa569
      anarcat authored
      a5caa569
    • anarcat's avatar
      fix crash: LDAP returns a string, cast it to an integer · 4ab5d834
      anarcat authored
      This fixes that crash which occurs on subsequent ud-generate runs:
      
      Traceback (most recent call last):
        File "/usr/bin/ud-generate", line 51, in <module>
          ud_generate()
        File "/usr/lib/python3/dist-packages/userdir_ldap/generate.py", line 1723, in ud_generate
          need_update = (ldap_last_mod > cache_last_ldap_mod) or (unix_last_mod > cache_last_unix_mod) or (time_started - last_run > MAX_UD_AGE)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      TypeError: '>' not supported between instances of 'str' and 'int'
      4ab5d834
  8. Sep 13, 2023
    • anarcat's avatar
      Merge branch 'install-restore-crash-0.3.104' · 44f2099e
      anarcat authored
      44f2099e
    • anarcat's avatar
      handle empty results from cn=log table · 78a397a2
      anarcat authored
      I have done a crazy buster -> bookworm upgrade of torproject.org's
      LDAP server, and it did as badly as you would expect.
      
      One thing that happened is both the main and `cn=log` databases were
      flushed. The main database was restored, but for some reason the
      second database couldn't be restore, or to be more accurate was
      restored as empty.
      
      This led the `sorted_mods` list there to be completely empty, which
      raised the following exception:
      
      root@alberti:/var/backups# sudo -u sshdist ud-generate
      Traceback (most recent call last):
        File "/usr/bin/ud-generate", line 51, in <module>
          ud_generate()
        File "/usr/lib/python3/dist-packages/userdir_ldap/generate.py", line 1715, in ud_generate
          ldap_last_mod = getLastLDAPChangeTime(lc)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3/dist-packages/userdir_ldap/generate.py", line 1615, in getLastLDAPChangeTime
          last = sorted_mods[-1][1]['reqEnd'][0].split(b'.')[0].decode('ascii')
                 ~~~~~~~~~~~^^^^
      IndexError: list index out of range
      
      That bit of defensive programming should work around such atrocities
      in the future.
      78a397a2
    • anarcat's avatar
      Merge branch 'bookworm-build-0.3.104' · 815898fa
      anarcat authored
      815898fa
    • anarcat's avatar
      fix implicit int to str cast that broke in bookworm (bullseye?) upgrade · d0740a95
      anarcat authored
      I'm not sure why we're using a string for one mod time and integers
      for all the others, but it's just not working anymore in Debian
      bookworm (and probably bullseye / Python 3+).
      
      This should fix the following backtrace:
      
      root@alberti:~# sudo -u sshdist ud-generate
      Traceback (most recent call last):
        File "/usr/bin/ud-generate", line 51, in <module>
          ud_generate()
        File "/usr/lib/python3/dist-packages/userdir_ldap/generate.py", line 1722, in ud_generate
          need_update = (ldap_last_mod > cache_last_ldap_mod) or (unix_last_mod > cache_last_unix_mod) or (time_started - last_run > MAX_UD_AGE)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      TypeError: '>' not supported between instances of 'int' and 'str'
      d0740a95
  9. Sep 09, 2023
  10. Jun 07, 2023
  11. May 30, 2023
  12. May 11, 2023
    • anarcat's avatar
      Merge branch 'fix-crash-without-exim-0.3.104' · 3a3add4c
      anarcat authored
      3a3add4c
    • anarcat's avatar
      ud-replicate: fix crash when exim is not installed · 51716ed4
      anarcat authored
      Without this, ud-replicate aborts halfway through with:
      
      root@submit-01:/var/lib/misc# ud-replicate
      receiving file list ... done
      submit-01.torproject.org/last_update.trace
      
      sent 44 bytes  received 936 bytes  1,960.00 bytes/sec
      total size is 245,745  speedup is 250.76
      chown: invalid group: ‘root:Debian-exim’
      
      ... unless exim4 is installed, which is not the case in the Tor
      Project (we use Postfix).
      
      There are similar guards elsewhere in the code, it seems it's just an
      oversight in this case.
      
      This issue only applies to hosts that do not have Exim installed *and*
      are SMTP submission servers.
      
      debian.org also has hosts that don't have Exim installed (lists and
      salsa both use Postifx) and ud-replicate works fine on them (because
      the code in question is never attempted on them).
      51716ed4
    • anarcat's avatar
      Merge branch 'fix-crash-without-exim-0.3.104' · fcd011e4
      anarcat authored
      fcd011e4
    • anarcat's avatar
      ud-replicate: fix crash when exim is not installed · b5881657
      anarcat authored
      Without this, ud-replicate aborts halfway through with:
      
      root@submit-01:/var/lib/misc# ud-replicate
      receiving file list ... done
      submit-01.torproject.org/last_update.trace
      
      sent 44 bytes  received 936 bytes  1,960.00 bytes/sec
      total size is 245,745  speedup is 250.76
      chown: invalid group: ‘root:Debian-exim’
      
      ... unless exim4 is installed, which is not the case in the Tor
      Project (we use Postfix).
      
      There are similar guards elsewhere in the code, it seems it's just an
      oversight in this case.
      b5881657
  13. May 10, 2023
    • anarcat's avatar
      Merge branch 'ssh-sk-0.3.104' · 404290e4
      anarcat authored
      404290e4
    • anarcat's avatar
      Merge branch 'dsa' · 6917667c
      anarcat authored
      6917667c
    • micah's avatar
      Add support for security key generated ssh public keys (sk- prefix). · a722f6f4
      micah authored and anarcat's avatar anarcat committed
      In 2020, OpenSSH 8.2 was released which supports FIDO (Fast Identity Online) U2F
      security keys. The public key type is used by hardware tokens, such as (but not
      limited to) Yubikeys, to generate a 'security key' (sk) public key of either
      `ecdsa-sk` or `ed25519-sk` key pairs.
      
      The `ed25519-sk` key type is only supported by new Yubikeys with firmware 5.2.3
      or higher, which supports FIDO2. Keys with firmware below that version are only
      compatible with `ecdsa-sk` key types.
      
      This change builds on caa57689 which added
      support for ecdsa-sha2-nistp256 keys, by also allowing for the `sk-` prefix for
      public keys.
      
      Ssh public keys generated on a security token will look like one of the
      following:
      
      sk-ecdsa-sha2-nistp256@openssh.com <public key material> <optional comment>
      
      or:
      sk-ssh-ed25519@openssh.com  <public key material> <optional comment>
      
      Note: the DoSSH() in ud-mailgate.py checks to make sure that a provided public
      key does not have newlines, but as implemented was only checking for three
      different key types (`ssh-rsa`, `ssh-ed25519`, and `ecdsa-sha2-nistp256`)
      userdir-ldap supports more types than those checked. Rather than just adding the
      two `sk-` key types to this check, and ignoring the other missing key types, I
      changed this check to mirror the regexp used to check for key types (with the
      regexp addition to confirm the keytype occurs on its own line, to indicate
      newlines were erroneously provided).
      a722f6f4
    • anarcat's avatar
      Merge branch 'sshfp-openssh-87' · 671d2d61
      anarcat authored
      671d2d61
    • anarcat's avatar
      disable SSHFP record for initramfs keys · 651f280c
      anarcat authored
      This is to mitigate an issue that came up with clients running OpenSSH
      8.7 or later. Before that release, it was acceptable to have multiple
      conflicting keys in DNS, just like it's okay to have multiple keys in
      known_hosts files. But starting from this commit:
      
      https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/dns.c.diff?r1=1.40&r2=1.41
      
      and this PR:
      
      https://github.com/openssh/openssh-portable/pull/259
      
      ... the check is hardened. This seems to have been introduced thanks
      to this bug report:
      
      https://bugzilla.mindrot.org/show_bug.cgi?id=3322
      
      The rationale was to warn about SHA1 records, but it actually warns
      about any duplicate record, as far as I can tell.
      
      An example of this problem is:
      
          anarcat@angela:~$ ssh dal-rescue-02.torproject.org
          @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
          @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
          @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
          IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
          Someone could be eavesdropping on you right now (man-in-the-middle attack)!
          It is also possible that a host key has just been changed.
          The fingerprint for the ED25519 key sent by the remote host is
          SHA256:l0wDT4pboFIfsZKrsreak6lGVQkPomc8GLdqYA25gf4.
          Please contact your system administrator.
          Update the SSHFP RR in DNS with the new host key to get rid of this message.
          Linux dal-rescue-02 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64
      
          [...]
          dal-rescue-02$
      
      We mitigate this by simply omitting duplicate records in the first
      place. We omit the initramfs entries which are the ones causing
      trouble in our case. Those are still available through the shared
      known_hosts file that doesn't trigger that problem.
      651f280c
    • anarcat's avatar
      Merge branch 'bookworm-build-0.3.104' · f7aaabd5
      anarcat authored
      f7aaabd5
    • anarcat's avatar
      fix warning about chown(1) call in bookworm · 25d89bdf
      anarcat authored
      This was giving us:
      
      chown: warning: '.' should be ':': ‘root.shadow’
      25d89bdf
    • anarcat's avatar
      fix Depends to support python3-only installs · 9c49a4ac
      anarcat authored
      9c49a4ac