Code Monkey home page Code Monkey logo

ipa-notify's Introduction

FreeIPA Notification

Upload Python Package

Notify IPA Users for password expiration and locked users to admin

Required packages:

  • krb5-devel
  • python3-pip
  • python3-virtualenv (Optional)
  1. Create a new role for notifier

    ipa role-add --desc "Notification agent role" "Notification Agent"
  2. Add privileges to the role

    ipa role-add-privilege "Notification Agent" --privileges="User Administrators"
    ipa role-add-privilege "Notification Agent" --privileges="Group Administrators"
    ipa role-add-privilege "Notification Agent" --privileges="Password Policy Readers"
  3. Create a new service and assign the role to this service

    ipa service-add NOTIFY/ipa1.example.com
    ipa role-add-member  "Notification Agent" --services="NOTIFY/[email protected]"
    ipa service-allow-retrieve-keytab "NOTIFY/[email protected]" --hosts=ipa1.example.com
  4. Obtain a keytab with fix permissions

    ipa-getkeytab -s ipa1.example.com -p "NOTIFY/[email protected]" -k ~/.priv/notify.keytab
    chmod -R 600 ~/.priv
  5. (Optional) Create a new virtual env and activate it

    mkdir /opt/ipa-notify
    virtualenv -p python3 /opt/ipa-notify/venv
    source /opt/ipa-notify/venv/bin/activate
  6. Install this package:

    pip3 install ipa-notify
  7. Run the command in noop mode for a successful user listing

    /opt/ipa-notify/bin/ipa-notify --server ipa1.example.com -p "NOTIFY/[email protected]" -k ~/.priv/notify.keytab \
    --limit 10 --groups users --check-expiration --noop
  8. Create a script includes the command with your parameters with proper permissions under /usr/local/sbin/

  9. Add a crontab entry. For example 0 0 * * * root /usr/local/sbin/ipa_notify.sh &>> /var/log/ipa_notify.log

  10. (Optional) You can create an email template folder and overwrite the message content. You can change the content but do not change file names or variable names. Template should start with Subject: keyword and there has to be new line between the subject and body. Please test your template before using.

$ python3 -c 'import ipa_notify;print(ipa_notify.__file__)'
/usr/local/lib/python3.6/site-packages/ipa_notify/__init__.py
$ cp -r /usr/local/lib/python3.6/site-packages/ipa_notify/templates ./mytemplates
# edit the content
$ ipa-notify ... --templates ./mytemplates

Parameters:

$ ipa-notify --help
usage: ipa-notify [-h] [--server SERVER] [--verify-ssl] [--no-verify-ssl] [--principal PRINCIPAL] [--keytab KEYTAB] [--groups GROUPS [GROUPS ...]] [--limit LIMIT] [--smtp-host SMTP_HOST] [--smtp-port SMTP_PORT]
                  [--smtp-security {none,STARTTLS,SSL}] [--smtp-user SMTP_USER] [--smtp-pass SMTP_PASS] [--smtp-from SMTP_FROM] [--admins ADMINS [ADMINS ...]] [--noop] [--check-expiration] [--check-locked] [--templates TEMPLATES]
                  [--log-level {CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}]

IPA Notifier

optional arguments:
  -h, --help            show this help message and exit
  --server SERVER       ipa server fqdn (default: ipa.domain.com)
  --verify-ssl          verify ipa connection SSL cert (default) (default: True)
  --no-verify-ssl       do not verify ipa connection SSL cert (default: True)
  --principal PRINCIPAL
                        user principal for kerberos authentication (default: [email protected])
  --keytab KEYTAB       keytab path (default: /tmp/user.kt)
  --groups GROUPS [GROUPS ...]
                        list of user groups to check (default: ['users'])
  --limit LIMIT         number of days before notifying a user (default: 5)
  --smtp-host SMTP_HOST
                        smtp host for sending email (default: localhost)
  --smtp-port SMTP_PORT
                        smtp port for sending email (default: 25)
  --smtp-security {none,STARTTLS,SSL}
                        smtp port for sending email (default: none)
  --smtp-user SMTP_USER
                        smtp user login (default: )
  --smtp-pass SMTP_PASS
                        smtp user password (default: )
  --smtp-from SMTP_FROM
                        smtp from email address (default: [email protected])
  --admins ADMINS [ADMINS ...]
                        admin user(s) email(s) to notify about locked users (default: [email protected])
  --noop                no operation mode. Do not send emails (default: False)
  --check-expiration    Check password expirations for users (default: False)
  --check-locked        Check locked out users (default: False)
  --templates TEMPLATES
                        Custom email template folder (default: )
  --log-level {CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}
                        log level (default: INFO)

ipa-notify's People

Contributors

cagdasbas avatar

Stargazers

 avatar Masanobu Yamagata avatar Roman Khmelichek avatar Abhas Abhinav avatar Jonathan Correa Paiva avatar  avatar

Watchers

Abhas Abhinav avatar James Cloos avatar  avatar  avatar

Forkers

roland-github

ipa-notify's Issues

wrapper script issues

Hi,

installed the script but ipa-notify wrapper is failing (wrong main maybe, I'm not a python programmer).
Somehow works if module/script called directly.
Please check/see below out.
Are you aware of any other issues with freeipa 4.6?
Our freeipa server is calling other servers which are connected to it when receiving an ipa query on API, but it could be also related to our older freeipa install/upgrades which might have some bad legacy freeipa configs.

ipa-notify
Traceback (most recent call last):
File "/usr/local/bin/ipa-notify", line 11, in
load_entry_point('ipa-notify==0.2.1', 'console_scripts', 'ipa-notify')()
TypeError: main() missing 3 required positional arguments: 'args', 'client', and 'notifier'

thank you

just a suggestion/feature request about script run

I have added an argument named "--no-expiry-check" and an if statement in main.py (on our local install) so we can disable script expiry checks on demand and allow to run only account lock checks
This is useful when you need to run account locks checks more often than 24h, that way notifying only admins about locked accounts and limiting notifications to user password expiry to 1/day by running two different cron jobs.

Crash on users with no password

Having a ipa group which contains user with only key based authentication will fail as they do not have password and password expiry.
A try would be nice around this issue:

                        try:
                                email = user['mail'][0]
...
...
                                                except ValueError:
                                                        logging.error("email send error, aborting...")
                                                        break
                        except KeyError as err:
                                logging.error("no expiration or mail for %s", user['uid'][0])
                                continue

Detailed instructions

Detailed instructions
Please tell us in more detail what needs to be done halfway through point 4.
What command should be executed in NOOP and how to do it?
What script should you create?
When and where to download files from the repository?

I beg your pardon for my stupidity, this is the first time I do this

some feature requests

You may consider below as possible features

  • option to disable notification of users with expired password - if they are not disabled will receive emails every day until someone notice they are not active and disable their account
  • add user/full name as variable in mail templates for addressing people

thank you

User lock notification issue

We have freeipa multi-master setup.
When gathering account lock status it seems python-freeipa module query all masters and it is using only first value, not the same with the queried server in our case, so our test cases failed.
python-freeipa(https://python-freeipa.readthedocs.io/en/latest/):
user_status(a_useruid, o_all=True, o_raw=False)
Lockout status of a user account
This connects to each IPA master and displays the lockout status on each one.
code:
<------>if int(user_status['result'][0]['krbloginfailedcount'][0]) >= ....
krbLoginFailedCount is not replicated to all masters being treated only locally on the master which was used when authentication failed.
Would be nice to have reports with login locks and associated freeipa master server name/fqdn since we need to unlock the user on that specific master.

email security none is not working as expected

Email security none is not working. It is trying to auth by user/pass.
None should be an option to use the host's local relay/local email service which do not require user/password.
Avoid below when security set to none:

                                smtp_conn.login(self.user, self.password)
                                logging.debug("smtp login successful")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.