aboutsummaryrefslogtreecommitdiffstats
path: root/roles/freeipa_server/tasks/custom_schema.yml
blob: 849b524130f4a142b5588998ca4ca2412c34ce38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
- name: create custom schema directory
  file:
    path: '{{ freeipa_custom_schema_dir }}'
    state: directory
    recurse: yes

- name: copy custom schemas
  copy:
    src: '{{ freeipa_custom_schema_dir[1:] }}/{{ item }}.ldif'
    dest: '{{ freeipa_custom_schema_dir }}/{{ item }}.ldif'
  loop:
    - jid
    - matrix
    - mastodon


# begin JIDObject schema
- name: check if JIDObject exists in schema
  shell: ldapsearch -QLLL -s base -b cn=schema objectclasses | grep -q JIDObject
  changed_when: no
  failed_when: no
  register: ldapsearch_jidobject

- block:
    - name: extend freeipa schema for JIDs
      command: ipa-ldap-updater --schema-file '{{ freeipa_custom_schema_dir }}/jid.ldif'

    - name: restart httpd
      systemd:
        name: httpd
        state: restarted
  when: ldapsearch_jidobject.rc != 0

- name: add index to jid attribute
  ldap_entry:
    dn: 'cn=jid,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config'
    objectClass:
      - top
      - nsIndex
    attributes:
      cn: jid
      nsSystemIndex: false
      nsIndexType: eq
    bind_dn: cn=Directory Manager
    bind_pw: '{{ freeipa_ds_password }}'
    server_uri: ldaps://{{ ipa_host }}
  register: jid_index

- name: regenerate indexes for jid attribute
  ldap_entry:
    dn: cn=jidindex,cn=index,cn=tasks,cn=config
    objectClass:
      - top
      - extensibleObject
    attributes:
      cn: jidindex
      nsInstance: userRoot
      nsIndexAttribute: 'jid:eq'
    bind_dn: cn=Directory Manager
    bind_pw: '{{ freeipa_ds_password }}'
    server_uri: ldaps://{{ ipa_host }}
  when: jid_index.changed
# end JIDObject schema

# begin matrixUser schema
- name: check if matrixUser exists in schema
  shell: ldapsearch -QLLL -s base -b cn=schema objectclasses | grep -q matrixUser
  changed_when: no
  failed_when: no
  register: ldapsearch_matrixuser

- block:
    - name: extend freeipa schema for matrix usernames
      command: ipa-ldap-updater --schema-file '{{ freeipa_custom_schema_dir }}/matrix.ldif'

    - name: restart httpd
      systemd:
        name: httpd
        state: restarted
  when: ldapsearch_matrixuser.rc != 0

- name: add index to matrixUsername attribute
  ldap_entry:
    dn: 'cn=matrixUsername,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config'
    objectClass:
      - top
      - nsIndex
    attributes:
      cn: matrixUsername
      nsSystemIndex: false
      nsIndexType: eq
    bind_dn: cn=Directory Manager
    bind_pw: '{{ freeipa_ds_password }}'
    server_uri: ldaps://{{ ipa_host }}
  register: matrixusername_index

- name: regenerate indexes for matrixUsername attribute
  ldap_entry:
    dn: cn=matrixusernameindex,cn=index,cn=tasks,cn=config
    objectClass:
      - top
      - extensibleObject
    attributes:
      cn: matrixusernameindex
      nsInstance: userRoot
      nsIndexAttribute: 'matrixUsername:eq'
    bind_dn: cn=Directory Manager
    bind_pw: '{{ freeipa_ds_password }}'
    server_uri: ldaps://{{ ipa_host }}
  when: matrixusername_index.changed
# end matrixUser schema

# begin mastodonUser schema
- name: check if mastodonUser exists in schema
  shell: ldapsearch -QLLL -s base -b cn=schema objectclasses | grep -q mastodonUser
  changed_when: no
  failed_when: no
  register: ldapsearch_mastodonuser

- block:
    - name: extend freeipa schema for mastodon usernames
      command: ipa-ldap-updater --schema-file '{{ freeipa_custom_schema_dir }}/mastodon.ldif'

    - name: restart httpd
      systemd:
        name: httpd
        state: restarted
  when: ldapsearch_mastodonuser.rc != 0

- name: add index to mastodonUsername attribute
  ldap_entry:
    dn: 'cn=mastodonUsername,cn=index,cn=userRoot,cn=ldbm database,cn=plugins,cn=config'
    objectClass:
      - top
      - nsIndex
    attributes:
      cn: mastodonUsername
      nsSystemIndex: false
      nsIndexType: eq
    bind_dn: cn=Directory Manager
    bind_pw: '{{ freeipa_ds_password }}'
    server_uri: ldaps://{{ ipa_host }}
  register: mastodonusername_index

- name: regenerate indexes for mastodonUsername attribute
  ldap_entry:
    dn: cn=mastodonusernameindex,cn=index,cn=tasks,cn=config
    objectClass:
      - top
      - extensibleObject
    attributes:
      cn: mastodonusernameindex
      nsInstance: userRoot
      nsIndexAttribute: 'mastodonUsername:eq'
    bind_dn: cn=Directory Manager
    bind_pw: '{{ freeipa_ds_password }}'
    server_uri: ldaps://{{ ipa_host }}
  when: mastodonusername_index.changed
# end mastodonUser schema

- name: add default user object classes
  ldap_attrs:
    dn: cn=ipaConfig,cn=etc,{{ freeipa_basedn }}
    attributes:
      ipaUserObjectClasses:
        - mailRecipient
        - JIDObject
        - matrixUser
        - mastodonUser
    state: present
    bind_dn: cn=Directory Manager
    bind_pw: '{{ freeipa_ds_password }}'
    server_uri: ldaps://{{ ipa_host }}

- name: add default group object classes
  ldap_attrs:
    dn: cn=ipaConfig,cn=etc,{{ freeipa_basedn }}
    attributes:
      ipaGroupObjectClasses:
        - mailRecipient
    state: present
    bind_dn: cn=Directory Manager
    bind_pw: '{{ freeipa_ds_password }}'
    server_uri: ldaps://{{ ipa_host }}

- name: allow read access to custom user attributes
  ipapermission:
    ipaadmin_principal: '{{ ipa_user }}'
    ipaadmin_password: '{{ ipa_pass }}'
    name: 'System: Read User Addressbook Attributes'
    attrs:
      - mailAlternateAddress
      - jid
      - matrixUsername
      - mastodonUsername
    action: member
    state: present

- name: allow read access to custom group attributes
  ipapermission:
    ipaadmin_principal: '{{ ipa_user }}'
    ipaadmin_password: '{{ ipa_pass }}'
    name: 'System: Read Groups'
    attrs:
      - mail
      - mailAlternateAddress
    action: member
    state: present