Bag attributes in OpenSSL PEM files seem to be a side effect of converting a PKCS#12 keypair into PEM format. An example is here:
Export PKCS12 files to PEM format using OpenSSL
If you're creating a PKCS#12 file using openssl, some of the command line arguments correlate to the bag attributes, and you can set them that way:
-name friendlyname
This specifies the "friendly name" for the certificate and private
key. This name is typically displayed in list boxes by software
importing the file.
-caname friendlyname
This specifies the "friendly name" for other certificates. This
option may be used multiple times to specify names for all
certificates in the order they appear. Netscape ignores friendly
names on other certificates whereas MSIE displays them.
-CSP name
Write name as a Microsoft CSP name.
This page describes how to remove Bag Attributes by converting PKCS#12 to PEM, trimming the PEM, and converting PEM back to PKCS#12 - not what you're looking for, but illustrative. You might be able to alter some bag attributes by converting, editing, converting back (although I wouldn't expect anything good to come out of modifying the localKeyID, for example)