samba share with AD security group auth

I'm having a hard time getting to authenticate Windows Active Directory security group to SAMBA shares. I am using CentOS 7 and SAMBA 4.

Does anyone have a working smb.conf file I can look at and also tell me what security permissions and groups to give to the directory in CentOS? Preferable one with modify and one with read only. Directory example /data/share

Posted Sep 7, 2017, 1:54 PM UTC

612
fakefadingOP•
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.

[global]
    workgroup = COLLEGECOLLEGEEDU
    server string = Samba Server Version %v

    hosts allow = 127. 172.

    log file = /var/log/samba/log.%m

    max log size = 50

    security = ads
    encrypt passwords = yes
    passdb backend = tdbsam
    realm = college.college.EDU


    printing = cups
    printcap name = cups
    load printers = yes
    cups options = raw

[homes]
    comment = Home Directories
    valid users = %S, %D%w%S
    browseable = No
    read only = No
    inherit acls = Yes

[printers]
    comment = All Printers
    path = /var/tmp
    printable = Yes
    create mask = 0600
    browseable = No

[print$]
    comment = Printer Drivers
    path = /var/lib/samba/drivers
    write list = root
    create mask = 0664
    directory mask = 0775

[testdata]
    comment = Test share
    path = /data/testdata
    public = no
    writable = yes
    guest ok = no
    directory mask = 0775
    valid users = @"[email protected]"
2
w2brhce•

What errors are you getting? Do you know for sure its actually talking kerberos? Also, isn't the realm always UPPERCASE?

2
fakefadingOP•

True about the realm, and it is upper case in my smb.conf file. I just had to edit out my actual domain, sorry about that.

No error, it just doesn't let me get in to view the folder.

1
SquiffSquiff•

I have done this, it is not straightforward and there are all sorts of pitfalls. There isn't a 'right' solution either which doesn't help. I last did this with ansible. Below are the Ansible playbook and the server samba config template. You don't really need to understand Ansible to follow these. N.B. I was required to use winbind instead of sssd. :( I am also aware that it is not ideal to import some of the config files such as /etc/pam.d/system-auth-ac

---
# tasks file for squiffsquiff.sambatest_winbind
      
  - name:   install winbind and samba packages
    yum: state=latest name={{ item }}
    with_items:
    - samba
    - samba-winbind
    - samba-winbind-clients 
    - krb5-workstation 
    - pam_krb5 
    - cifs-utils
    - ntpdate

  - name: set permissions on /usr/sbin/mount.cifs
    file:
      path: /usr/sbin/mount.cifs
      state: touch
      mode: "u+s"
      
  - name: authconfig tasks
    shell: authconfig --enablewinbind --enablewinbindauth --enablemkhomedir --update

  - name: import new /etc/pam.d/password-auth-ac
    copy: 
      src: password-auth-ac
      dest: /etc/pam.d/password-auth-ac
      owner: root
      group: root
      mode: 0644
      backup: yes
      
  - name: import new /etc/pam.d/system-auth-ac 
    copy: 
      src: system-auth-ac
      dest: /etc/pam.d/system-auth-ac
      owner: root
      group: root
      mode: 0644
      backup: yes 
      
  - name: import new /etc/ntp.conf
    copy: 
      src: ntp.conf
      dest: /etc/ntp.conf
      owner: root
      group: root
      mode: 0644
      backup: yes      
      
  - name: import new pam_winbind.conf
    copy: 
      src: pam_winbind.conf
      dest: /etc/security/pam_winbind.conf
      owner: root
      group: root
      mode: 0644
      backup: yes  
      
  - name: ensure samba shared directory exists
    file: 
      path: /mnt/permissions_test/
      state: directory 
      mode: 0777
      group: "domain users"   
      
  - name: ensure samba shared subdirectory 'share' exists
    file: 
      path: /mnt/permissions_test/share
      state: directory 
      mode: 0777
      group: "root"         
      
  - name: set default acl for for subdirectory 'share' 
    acl:
      path: /mnt/permissions_test/share
      entity: "domain users"
      etype: group
      permissions: r--
      default: yes
      state: present 
       
  - name: Samba configuration
    template:
      dest: /etc/samba/smb.conf
      src: smb.conf.j2
      validate: 'testparm -s %s'     
      
  - name: enable and start ntpdate   
    service: 
      name: ntpdate 
      enabled: yes
      state: restarted   

  - name: Join AD with Samba to generate the keytab
    command: /usr/bin/net ads join -U administrator%AdMiNPaSsWoRd
                
  - name: enable and start winbind   
    service: 
      name: winbind 
      enabled: yes
      state: restarted  

  - name: ensure Samba is started and enabled on boot
    service: 
      name: smb
      state: restarted 
      enabled: yes    
      
  - name: ensure nmb is started and enabled on boot
    service: 
      name: nmb
      state: restarted 
      enabled: yes   

  - name: create firewall rule to allow samba     
    firewalld:
      service: samba
      permanent: true
      state: enabled
  
  # Only enable   if actually using firewall
  #- name: reload firewall rules
    #service: 
      #name: firewalld
      #state: reloaded

And the server smb.conf template

# Samba configuration -- Managed by Ansible, please don't edit manually
# vim: ft=samba
#
# {{ ansible_managed }}

[global]
netbios name = {{ ansible_hostname }}
workgroup = COLLEGE
security = ADS
realm = COLLEGE.LAN
encrypt passwords = yes
#kerberos method = secrets and keytab
kerberos method = system keytab
winbind refresh tickets = yes

idmap config *:backend = tdb
idmap config *:range = 50001-60000

idmap config COLLEGE:backend = ad
idmap config COLLEGE:schema_mode = rfc2307
idmap config COLLEGE:range = 20000-30000

winbind nss info = rfc2307
winbind trusted domains only = no
winbind use default domain = yes
winbind enum users  = yes
winbind enum groups = yes

winbind cache time = 1
idmap negative cache time = 1
#winbind offline logon = true

server signing = auto
client signing = auto

store dos attributes = yes
inherit acls = yes

#map acl inherit = yes
#vfs objects = acl_xattr
#acl_xattr:ignore system acls = yes

template shell = /bin/bash

##########################
Share definitions
###########################

[permissions_test]
        path = /mnt/permissions_test/
        read only = No
#        create mask = 1644      
        create mask = 1640
#        directory mask = 0777       
        directory mask = 1750

You also need a matching AD (win)bind on the clients

2
fakefadingOP•

Thank you. I've never used the taskfile for squiff.squiff before. How do I use that?

1
SquiffSquiff•

You don't. That's an ansible playbook header (i.e. comment). In Ansible you have a playbook which specifies tasks to be completed in order. Here each task is commented. I have not provided the full ansible role so some of the files referenced are not available to you but you can see that you need to attend to things like authconfig and ntp in your setup

2
fakefadingOP•

Thank you, I haven't installed winbind yet, I need to do that first.

1
SquiffSquiff•

sssd is preferable tbh

1
solteranis•

Below is an example of my Global section, and a single share on my CentOS 6.9 server using Samba4.

Please note, there are things in here you may not need, and I'm sure I have a few "Redundant" settings in here lol.

However, this does work. You were recommended to use SSSD, which believe me is a fantastic auth mechanism (I use it everywhere as it just works great), however I did have to install winbind to make this work.

As for directory permissions you'll need to become familiar with setfacl/getfacl. Additionally you'll need to ensure your partition supports this (most do, but it's worth checking). Basically setfacl the directories so domain admins have full access, and then setfacl for the permissions you want the group to have.

Once the initial setup is complete, it's actually easier to setup the permissions in some cases using windows explorer like you would a windows share (although I still prefer the command line).

Other things to note, you'll need to join the system to the domain with a "net ads join -U ADMIN_USER", configure /etc/nsswitch, and a few more things. I highly recommend using the below guide:

https://wiki.samba.org/index.php/Setting_up_a_Share_Using_Windows_ACLs

For more info on each of the options in my config:

https://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html

[global]
#-------Server Settings-------#
  workgroup = MYDOMAIN
  server string = Description
  netbios name = myserver

#-----Log Settings------#
#---%U=Session Username---#
#---%m=NetBios Machine---#
#  log level = 3
  log file = /var/log/samba/log.%U.%m
  max log size = 10240

#-----Allowed Users-----#
  valid users = @"Domain Admins",@"OtherAD Groups"

#------Security Settings------#
  security = domain
  encrypt passwords = yes
  password server = *

#------Realm and AD Settings
  realm = MYDOMAIN.TLD
  template shell = /bin/bash

  idmap backend = idmap_rid:MYDOMAIN=500-1000000
  idmap uid = 500-1000000
  idmap gid = 500-1000000

  idmap config * : backend = tdb
  idmap config * : range = 1000001-2000000

  idmap config MYDOMAIN : backend = rid
  idmap config MYDOMAIN : range = 10000-49999

#-------Winbind Settings-------#
  winbind refresh tickets =  yes
  winbind nss info = rfc2307
  winbind separator = \\
  winbind trusted domains only = yes
  winbind use default domain = yes
  winbind enum users = yes
  winbind enum groups = yes

#-------Windows ACL Settings------#
  vfs objects = acl_xattr, full_audit, recycle
  map acl inherit = yes
  store dos attributes = yes

[SHARE_NAME]
  path = /path_to_share
  read only = no
  inherit permissions = yes
  inherit acls = yes
  ea support = yes
  map acl inherit = yes
  map hidden = no
  map system = no
  map archive = no
  map readonly = no
  store dos attributes = yes

  vfs objects = full_audit, acl_xattr, recycle

  full_audit:success = chdir mkdir rmdir read pread write pwrite rename unlink sendfile
  full_audit:prefix = %u|%I|%m|%S
  full_audit:failure = connect
  full_audit:facility = local5
  full_audit:priority = notice

  recycle:repository = /path/%u
  recycle:directory_mode = 0700
  recycle:subdir_mode = 0700
  recycle:keeptree = yes
  recycle:versions = yes
  recycle:touch_mtime = yes
1
fakefadingOP•

Awesome thank you! I apprecieate this very much! I hope to have a share working by the end of the week lol

1
I12crash•

You may want to check out Centrify. That's what we have been using for everything from RHEL 5 (I'm embarrassed to admit that) to RHEL 7. It makes the setup of Samba shares very straight forward and simple. It's free as long as you don't have more thn 200 hosts. https://community.centrify.com/t5/TechBlog/Server-Suite-2016-Samba-with-adbindproxy/ba-p/24052

1
fakefadingOP•

Awesome, thank you I had never even heard of this. I'll definitely check this out!

1