The circumstances under which you can publish privately (i.e. not in your role as employee) depend on your employment contract and on your jurisdiction. It is not uncommon to have a clause that requires you to ask your employer for permission before you may publish anything.
Generally, your employer does not have any rights to works that you create on your own time, with your personal resources. And companies are generally interested to have “expert” employees – if I'm looking for a job and see that my future coworkers have published open source code, that's a big plus (assuming the code is decent). However, there are circumstances where an employer has a legitimate interest in not letting you publish privately:
The work to be published would disclose trade secrets or internals of your employer. If any competitors would get an advantage from looking at your publication, maybe it's not a good idea to publish it.
The work may have technically been produced outside of the employment, but was clearly inspired by experiences within the employment.
The work would reflect badly on the employer.
By publishing the work, you would compete with your employer.
Publishing open-source code is not fundamentally different from publishing a book with respect to employment.
If your proposed work might be relevant in one of these ways to your employer, it is correct to ask your boss whether they have any objections – ideally before you start any serious work on the project. Reactions may include:
- a cease and desist letter
- a request to please not publish this
- a request to state that this is your personal opinion and not that of your employer
- a request to mention your employer
- a go ahead, with a request to review the work before it is published
- a go ahead, and wishing you lots of fun
- an offer to create the work as part of your employment
What exactly you are permitted to do, what your employer is permitted to do, and what you are required to do, depends on your local laws and on the contents of your employment contract. If your employer says “no”, this may or may not be legal – but it would usually be unwise to strain your employment relationship over this.
If you like contributing to open source, it's a good idea to keep an eye on the section about IP in the contract for your next job. If possible, it may also be sensible to do any open-source work with a different tech stack and in a different problem domain than within your employment – that way it's absolutely clear that your employer has no rights over this work, and you won't get the feeling that you're doing unpaid work for your employer.