Bug 16285 - net ads join fails with pre-created machine accounts
Summary: net ads join fails with pre-created machine accounts
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: AD: LDB/DSDB/SAMDB (show other bugs)
Version: 4.24.7
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Samba QA Contact
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-10-20 01:56 UTC by Wade Cline
Modified: 2026-11-04 21:38 UTC (History)
3 users (show)

See Also:


Attachments
sudo net -d 10 --machine-pass ads join ${DOMAIN_FQDN} (15.49 KB, application/gzip)
2026-10-20 01:56 UTC, Wade Cline
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wade Cline 2026-10-20 01:56:08 UTC
Created attachment 19300 [details]
sudo net -d 10 --machine-pass ads join ${DOMAIN_FQDN}

We (non AD-admin workers) have been using 'net ads join' in order to join our computers to the Active Directory domain.
The AD admins provide us a Web portal which we use in order to pre-create computer objects.
The Web portal was recently migrated to a new backend;
computer objects created using the new backend are unable to join the domain using 'net ads join'.
This is in part due to a security-related change to migrate away from domain joining using user Kerberos tickets to computer object-specific passwords.
The known relevant changes between the old and new backend are:

  * Old backend:
    * Computer object properties:
      * managedBy: User's Distinguished Name (DN)
      * userAccountControl: 4128
      * servicePrincipalName: Set
      * dNSHostName: Set
    * Join via user Kerberos ticket with: 'net --use-kerberos=required ads join ${DOAMIN}'
  * New backend:
    * Computer object properties:
      * managedBy: Unset
      * userAccountControl: 4096
      * servicePrincipalName: Unset
      * dNSHostName: Unset
    * Join via computer object password with: 'net --machine-pass ads join ${DOAMIN}'

The full domain join steps we attempted are:

  1. Configure Kerberos ('/etc/krb5.conf.d/mycorp.conf')
  2. Obtain user Kerberos ticket ('kinit')
  3. Configure '/etc/samba/smb.conf':

     [global]
     security=ads
     realm=${DOMAIN_FQDN}
     workgroup=${DOMAIN}
     winbind use default domain = yes
     winbind offline logon = yes
     winbind refresh tickets = yes
     winbind enum users = no
     winbind enum groups = no
     winbind cache time = 864000
     netbios name = ${COMPUTER_OBJECT_NAME}
     create krb5 conf = yes
     log level = 0 auth:10 winbind:10
     kerberos method = secrets and keytab

  4. Configure '/etc/security/pam_winbind.conf'

     cached_login = yes
     krb5_auth = yes
     krb5_ccache_type = FILE

  5. Use 'net ads join' in order to join the domain
     a. Joining using the user Kerberos ticket fails (expected as 'managedBy' is not set):
        $ sudo net --use-kerberos=required ads join ${DOMAIN_FQDN}
        ads_print_error: AD LDAP ERROR: 50 (Insufficient access): 00000522: SecErr: DSID-031538EC, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0
        
        Failed to join domain: User specified does not have administrator privileges
     b. Joining using the computer object password fails (unexpected):
        $ sudo net -U '%{HOSTNAME}%${COMPUTER_OBJECT_PASSWORD}' ads join ${DOMAIN_FQDN}
        ads_print_error: AD LDAP ERROR: 50 (Insufficient access): 00000005: SecErr: DSID-031A11CF, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0
        
        Failed to join domain: Failed to set account flags for machine account (NT_STATUS_ACCESS_DENIED)
     c. Joining using a computer object password in the TDB fails (unexpected):
        $ sudo net setdomainsid ${SID}
        $ sudo tdbtool /var/lib/samba/private/secrets.tdb store SECRETS/MACHINE_LAST_CHANGE_TIME/${DOMAIN} '2\00'
        $ sudo tdbtool /var/lib/samba/private/secrets.tdb store SECRETS/MACHINE_PASSWORD/${DOMAIN} '2\00'
        $ sudo net changesecretpw -f
        $ sudo net --machine-pass ads join ${DOMAIN_FQDN}
        ads_print_error: AD LDAP ERROR: 50 (Insufficient access): 00000005: SecErr: DSID-031A11CF, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0
        
        Failed to join domain: Failed to set account flags for machine account (NT_STATUS_ACCESS_DENIED)

We know that it's possible to join the domain using the computer object password because it's possible:

  1. On Windows 11
  2. On Fedora 44 using SSSD:
     $ sudo adcli join ${DOMAIN_FQDN}  --host-fqdn ${HOST_FQDN}  --computer-name ${COMPUTER_NAME}  --use-ldaps  --one-time-password="${COMPUTER_OBJECT_PASSWORD}"  --verbose
  3. On Fedora 44 "manually" with samba (see below)

The "manual" process is rather long and convoluted, but it does appear to work:

  1. Configure Kerberos ('/etc/krb5.conf.d/mycorp.conf')
  3. Create the '/etc/samba/smb.conf' file
  4. Configure '/etc/security/pam_winbind.conf'
  5. Set the domain SID.
     Without this step the 'net changesecretpw' command won't be able to set the computer object password.
     a. Find a domain server: $ nslookup -type=SRV _ldap._tcp.${DOMAIN_FQDN}
     b. Get the SID using the computer object password: $ rpcclient -U '${COMPUTER_NAME}%${COMPUTER_OBJECT_PASSWORD}' ${DOMAIN_SERVER_FQDN} -c 'lsaquery' 
     c. Set the SID: $ sudo net setdomainsid ${SID}
  6. Set the computer object password in the TDB:
     a. sudo tdbtool /var/lib/samba/private/secrets.tdb store SECRETS/MACHINE_LAST_CHANGE_TIME/${DOMAIN} '2\00'
     b. sudo tdbtool /var/lib/samba/private/secrets.tdb store SECRETS/MACHINE_PASSWORD/${DOMAIN} '2\00'
     c. sudo net changesecretpw -f
  7. Obtain computer Kerberos ticket.
     This is required in order to set the computer object's 'dNSHostName' and 'servicePrincipalName'
     $ sudo net --machine-pass ads kerberos kinit
  8. Set required computer object attributes via LDAP:
     Without 'servicePrincipalName', computer object keytab generation ('net ads keytab create'; not to be confused with kerberos ticket creation) will fail with 'pw2kt_get_dc_info: Failed to determine servicePrincipalName.'
     Without 'dNSHostName', setting 'servicePrincipalName' will fail due to a constraint on the LDAP server.
     a. Set 'dNSHostName':
        $ sudo KRB5CCNAME=/tmp/krb5cc_0 ldapmodify -Y GSSAPI -H ldap://${DOMAIN_SERVER_FQDN} << EOF
        dn: ${COMPUTER_OBJECT_DISTINGUISHED_NAME}
        changetype: modify
        add: dNSHostName
        dNSHostName: ${COMPUTER_OBJECT_HOSTNAME}
        EOF
     b. Set 'servicePrincipalName':
        $ sudo KRB5CCNAME=/tmp/krb5cc_0 ldapmodify -Y GSSAPI -H ldap://${DOMAIN_SERVER_FQDN} << EOF
        dn: ${COMPUTER_OBJECT_DISTINGUISHED_NAME}
        changetype: modify
        add: servicePrincipalName
        servicePrincipalName: HOST/${COMPUTER_OBJECT_FQDN}
        servicePrincipalName: HOST/${COMPUTER_OBJECT_HOSTNAME}
        EOF
  9. Enable & start the 'winbind' service
 10. Generate the computer object keytab using the initial computer object password: $ sudo net --machine-pass ads keytab create
 11. Select 'winbind' as the preferred authentication method: $ sudo authselect select winbind --force
 12. Wait for the domain to come online: $ wbinfo --domain="${DOMAIN}" --online-status
 13. Rotate the machine password: $ sudo net --machine-pass rpc changetrustpw -S ${DOMAIN_SERVER_FQDN}
 14. Update the computer object keytab with the new computer object password: $ sudo net --machine-pass ads keytab create

Obviously, this is not ideal.

Attached is a 'sudo net -d 10 --machine-pass ads join ${DOMAIN_FQDN}' logfile with potentially sensitive information redacted.

Based on analyzing the logs, AI (Ornith 1.0, 9B) is convinced that the issue is that 'userAccountControl' on the new object is set to '4096', the join command is trying to set the 'DONT_EXPIRE_PASSWD' flag giving the value '4128', but the computer object doesn't have permission to set this flag, so the join is failing at this point.
The 'source3/libnet/libnet_join.c' code at line 1510 appears to correspond to this hypothesis:

	acct_flags |= ACB_PWNOEXP;

And this hypothesis seems to corroborate with the following log entry:

	ads_gen_mod: AD LDAP: Modifying ${COMPUTER_OBJECT_DISTINGUISHED_NAME}
	ads_dump_modlist: mod[0]: mod_op: LDAP_MOD_REPLACE | LDAP_MOD_BVALUES
	mod[0]: mod_type: unicodePwd
	ads_print_error: AD LDAP ERROR: 50 (Insufficient access): 00000005: SecErr: DSID-031A11CF, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0
	
	libnet_join_precreate_machine_acct: Failed to create machine account
	libnet_DomainJoin: Failed to pre-create account in OU ${OU_STUFF}: Insufficient access

There does not appear to be any kind of configuration option to prevent the join command from setting the 'DONT_EXPIRE_PASSWD' flag, so testing this would require modifying the source code.


Since "manually" joining the domain appears to work, I'd expect there to be a way to join the domain with the computer object's password using 'net ads join'.