Archived
feat: port legacy KNELSecretsManager (bw-* tooling, ADRs, tests) [#769]
Secret-scanned clean (placeholder values only). Bitwarden tooling is the head start for the Vaultwarden-SoR bootstrap (#770). legacy-* trees exempt from lint/pointer checks (historical verbatim code). https://projects.knownelement.com/issues/769#note-4152
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
# they don't need this file.
|
# they don't need this file.
|
||||||
|
|
||||||
# Project-specific overrides for check-rules.sh
|
# Project-specific overrides for check-rules.sh
|
||||||
export PROJECT_DOC_EXEMPT ?= AGENTS.md STATUS.md WORKING.md README.md ADOPTING.md LICENSE .env.example questions-v1.md BASELINE-PROMPT.md PATTERNS.md
|
export PROJECT_DOC_EXEMPT ?= legacy-* AGENTS.md STATUS.md WORKING.md README.md ADOPTING.md LICENSE .env.example questions-v1.md BASELINE-PROMPT.md PATTERNS.md
|
||||||
export PROJECT_DISCOURSE_HOST ?= community.turnsys.com
|
export PROJECT_DISCOURSE_HOST ?= community.turnsys.com
|
||||||
|
|
||||||
.PHONY: setup validate fast lint test garden up down status clean help
|
.PHONY: setup validate fast lint test garden up down status clean help
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# Bitwarden configuration files containing secrets
|
||||||
|
bitwarden-config.conf
|
||||||
|
bitwarden-config.conf.dev
|
||||||
|
*.conf
|
||||||
|
!*.conf.sample
|
||||||
|
|
||||||
|
# Test files
|
||||||
|
tests/test-bitwarden-config.conf
|
||||||
|
|
||||||
|
# Log files
|
||||||
|
*.log
|
||||||
|
/tmp/*.log
|
||||||
|
|
||||||
|
# Session files
|
||||||
|
.bw-session
|
||||||
|
|
||||||
|
# Generated documentation
|
||||||
|
COMMANDS.md
|
||||||
|
|
||||||
|
# Backup files
|
||||||
|
*.bak
|
||||||
|
*.backup
|
||||||
|
|
||||||
|
# OS specific files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Editor files
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
TSYSSecretsManager
|
||||||
|
Copyright (C) 2024 TechnicalOperations
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>.
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
# TSYS Secrets Manager - Makefile
|
||||||
|
# Provides convenient commands for testing, linting, and CI/CD
|
||||||
|
|
||||||
|
.PHONY: help test test-ci lint install clean check-deps vendor-test all
|
||||||
|
|
||||||
|
# Default target
|
||||||
|
all: check-deps lint test
|
||||||
|
|
||||||
|
help: ## Show this help message
|
||||||
|
@echo "TSYS Secrets Manager - Available Commands:"
|
||||||
|
@echo ""
|
||||||
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|
||||||
|
test: ## Run all tests
|
||||||
|
@echo "Running test suite..."
|
||||||
|
./tests/test-secrets-manager.sh run
|
||||||
|
|
||||||
|
test-ci: ## Run tests in CI mode (no colors, verbose output)
|
||||||
|
@echo "Running test suite in CI mode..."
|
||||||
|
./tests/test-secrets-manager.sh --ci run
|
||||||
|
|
||||||
|
test-setup: ## Setup test environment only
|
||||||
|
./tests/test-secrets-manager.sh setup
|
||||||
|
|
||||||
|
test-cleanup: ## Cleanup test environment
|
||||||
|
./tests/test-secrets-manager.sh cleanup
|
||||||
|
|
||||||
|
test-list: ## List available test functions
|
||||||
|
./tests/test-secrets-manager.sh list
|
||||||
|
|
||||||
|
lint: ## Run shell script linting with shellcheck
|
||||||
|
@echo "Running shellcheck..."
|
||||||
|
@if command -v shellcheck >/dev/null 2>&1; then \
|
||||||
|
shellcheck -x secrets-manager.sh tests/test-secrets-manager.sh bin/*.sh; \
|
||||||
|
echo "✓ Shellcheck passed"; \
|
||||||
|
else \
|
||||||
|
echo "⚠ Shellcheck not found, skipping lint check"; \
|
||||||
|
echo " Install with: apt install shellcheck"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
install: ## Install dependencies and setup environment
|
||||||
|
@echo "Installing dependencies..."
|
||||||
|
@if command -v apt >/dev/null 2>&1; then \
|
||||||
|
sudo apt update && sudo apt install -y shellcheck; \
|
||||||
|
elif command -v dnf >/dev/null 2>&1; then \
|
||||||
|
sudo dnf install -y ShellCheck; \
|
||||||
|
elif command -v yum >/dev/null 2>&1; then \
|
||||||
|
sudo yum install -y ShellCheck; \
|
||||||
|
else \
|
||||||
|
echo "⚠ Package manager not detected, please install shellcheck manually"; \
|
||||||
|
fi
|
||||||
|
@echo "Making scripts executable..."
|
||||||
|
chmod +x secrets-manager.sh tests/test-secrets-manager.sh bin/*.sh
|
||||||
|
|
||||||
|
check-deps: ## Check for required dependencies
|
||||||
|
@echo "Checking dependencies..."
|
||||||
|
@echo -n "bash: "; command -v bash >/dev/null 2>&1 && echo "✓" || echo "✗ Required"
|
||||||
|
@echo -n "shellcheck: "; command -v shellcheck >/dev/null 2>&1 && echo "✓" || echo "⚠ Optional (for linting)"
|
||||||
|
@echo -n "git: "; command -v git >/dev/null 2>&1 && echo "✓" || echo "⚠ Optional (for version control)"
|
||||||
|
@echo -n "make: "; command -v make >/dev/null 2>&1 && echo "✓" || echo "⚠ Optional (you're using it now)"
|
||||||
|
|
||||||
|
vendor-test: ## Test script as if vendored into another project
|
||||||
|
@echo "Testing vendor integration..."
|
||||||
|
@mkdir -p /tmp/vendor-test
|
||||||
|
@cp secrets-manager.sh config/bitwarden-config.conf.sample /tmp/vendor-test/
|
||||||
|
@cp tests/test-secrets-manager.sh /tmp/vendor-test/
|
||||||
|
@cd /tmp/vendor-test && chmod +x test-secrets-manager.sh && ./test-secrets-manager.sh --ci run
|
||||||
|
@rm -rf /tmp/vendor-test
|
||||||
|
@echo "✓ Vendor integration test passed"
|
||||||
|
|
||||||
|
clean: ## Clean up temporary files and logs
|
||||||
|
@echo "Cleaning up..."
|
||||||
|
@rm -f /tmp/secrets-manager*.log
|
||||||
|
@rm -f tests/test-bitwarden-config.conf
|
||||||
|
@rm -rf /tmp/vendor-test
|
||||||
|
@echo "✓ Cleanup complete"
|
||||||
|
|
||||||
|
validate-config: ## Validate sample configuration file
|
||||||
|
@echo "Validating configuration files..."
|
||||||
|
@if [ -f config/bitwarden-config.conf.sample ]; then \
|
||||||
|
echo "✓ Sample config exists"; \
|
||||||
|
grep -q "BW_SERVER_URL" config/bitwarden-config.conf.sample && echo "✓ Server URL configured" || echo "✗ Missing server URL"; \
|
||||||
|
grep -q "BW_CLIENTID" config/bitwarden-config.conf.sample && echo "✓ Client ID configured" || echo "✗ Missing client ID"; \
|
||||||
|
grep -q "BW_CLIENTSECRET" config/bitwarden-config.conf.sample && echo "✓ Client secret configured" || echo "✗ Missing client secret"; \
|
||||||
|
grep -q "BW_PASSWORD" config/bitwarden-config.conf.sample && echo "✓ Password configured" || echo "✗ Missing password"; \
|
||||||
|
else \
|
||||||
|
echo "✗ Sample config not found"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
security-check: ## Run basic security checks
|
||||||
|
@echo "Running security checks..."
|
||||||
|
@echo "Checking for hardcoded secrets..."
|
||||||
|
@if grep -r -i "password\|secret\|key" --include="*.sh" --exclude="*test*" . | grep -v "BW_" | grep -v "your_.*_here" | grep -v "test_" >/dev/null; then \
|
||||||
|
echo "⚠ Potential hardcoded secrets found:"; \
|
||||||
|
grep -r -i "password\|secret\|key" --include="*.sh" --exclude="*test*" . | grep -v "BW_" | grep -v "your_.*_here" | grep -v "test_"; \
|
||||||
|
else \
|
||||||
|
echo "✓ No hardcoded secrets detected"; \
|
||||||
|
fi
|
||||||
|
@echo "Checking file permissions..."
|
||||||
|
@find . -name "*.sh" -not -perm 755 -exec echo "⚠ Script not executable: {}" \; || echo "✓ Script permissions OK"
|
||||||
|
|
||||||
|
ci: check-deps lint test-ci security-check ## Run full CI pipeline
|
||||||
|
@echo "✓ CI pipeline completed successfully"
|
||||||
|
|
||||||
|
docs: ## Generate documentation
|
||||||
|
@echo "Generating documentation..."
|
||||||
|
@echo "Available commands:" > COMMANDS.md
|
||||||
|
@echo "" >> COMMANDS.md
|
||||||
|
@./secrets-manager.sh --help >> COMMANDS.md
|
||||||
|
@echo "" >> COMMANDS.md
|
||||||
|
@echo "Test commands:" >> COMMANDS.md
|
||||||
|
@echo "" >> COMMANDS.md
|
||||||
|
@./test-secrets-manager.sh --help >> COMMANDS.md
|
||||||
|
@echo "✓ Documentation generated in COMMANDS.md"
|
||||||
|
|
||||||
|
# Development helpers
|
||||||
|
dev-setup: install ## Setup development environment
|
||||||
|
@echo "Setting up development environment..."
|
||||||
|
@cp config/bitwarden-config.conf.sample bitwarden-config.conf.dev
|
||||||
|
@echo "✓ Development environment ready"
|
||||||
|
@echo " Edit bitwarden-config.conf.dev with your development credentials"
|
||||||
|
|
||||||
|
dev-test: ## Run tests with development config
|
||||||
|
@if [ -f bitwarden-config.conf.dev ]; then \
|
||||||
|
cp bitwarden-config.conf.dev bitwarden-config.conf; \
|
||||||
|
$(MAKE) test; \
|
||||||
|
rm -f bitwarden-config.conf; \
|
||||||
|
else \
|
||||||
|
echo "⚠ No development config found. Run 'make dev-setup' first."; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Version management
|
||||||
|
version: ## Show current version
|
||||||
|
@./secrets-manager.sh --version
|
||||||
|
|
||||||
|
release-check: ## Check if ready for release
|
||||||
|
@echo "Checking release readiness..."
|
||||||
|
@$(MAKE) ci
|
||||||
|
@echo "✓ All checks passed - ready for release"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Port provenance
|
||||||
|
|
||||||
|
Imported from KNEL/KNELSecretsManager@master (2026-09-04) per OQ2 ruling
|
||||||
|
(#769). Secret-scanned clean (placeholders only). The bw-* Bitwarden tooling
|
||||||
|
here is the practical head start for the Vaultwarden-SoR bootstrap (#770).
|
||||||
@@ -0,0 +1,267 @@
|
|||||||
|
# TSYS Secrets Manager
|
||||||
|
|
||||||
|
A comprehensive bash script solution for managing secrets at TSYS using the Bitwarden CLI. This tool provides automated installation, configuration, and secure secret retrieval from your Bitwarden vault.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Automated Installation**: Automatically detects and installs Bitwarden CLI via multiple methods (snap, npm, direct download)
|
||||||
|
- **Configuration Management**: Uses secure configuration files for server and authentication details
|
||||||
|
- **Multiple Commands**: Support for installation, secret retrieval, listing, and testing
|
||||||
|
- **Robust Error Handling**: Comprehensive error codes and detailed logging
|
||||||
|
- **Security-First**: Proper session management, cleanup, and credential handling
|
||||||
|
- **Cross-Platform**: Designed for Linux environments with multiple installation fallbacks
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
1. **Clone and Setup**:
|
||||||
|
```bash
|
||||||
|
git clone <repository-url>
|
||||||
|
cd KNELSecretsManager
|
||||||
|
chmod +x secrets-manager.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Create Configuration**:
|
||||||
|
```bash
|
||||||
|
cp config/bitwarden-config.conf.sample bitwarden-config.conf
|
||||||
|
# Edit bitwarden-config.conf with your actual Bitwarden credentials
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Install Bitwarden CLI** (if not already installed):
|
||||||
|
```bash
|
||||||
|
./secrets-manager.sh install
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Test Your Setup**:
|
||||||
|
```bash
|
||||||
|
./secrets-manager.sh test
|
||||||
|
```
|
||||||
|
|
||||||
|
5. **Retrieve Secrets**:
|
||||||
|
```bash
|
||||||
|
./secrets-manager.sh get APIKEY-pushover
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Create a `bitwarden-config.conf` file based on the provided sample in the `config/` directory:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Bitwarden server URL
|
||||||
|
BW_SERVER_URL="https://pwvault.turnsys.com"
|
||||||
|
|
||||||
|
# API credentials (from Bitwarden account settings)
|
||||||
|
BW_CLIENTID="your_client_id_here"
|
||||||
|
BW_CLIENTSECRET="your_client_secret_here"
|
||||||
|
|
||||||
|
# Master password
|
||||||
|
BW_PASSWORD="your_master_password_here"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Security Note**: The actual configuration file is automatically ignored by git to prevent credential exposure.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Command Reference
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./secrets-manager.sh [OPTIONS] COMMAND [ARGS]
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Commands
|
||||||
|
|
||||||
|
- **`install`** - Install Bitwarden CLI
|
||||||
|
- **`get <secret_name>`** - Retrieve a specific secret
|
||||||
|
- **`list`** - List all available secrets in your vault
|
||||||
|
- **`test`** - Test configuration and connectivity
|
||||||
|
|
||||||
|
#### Options
|
||||||
|
|
||||||
|
- **`-c, --config FILE`** - Use specific config file (default: `./bitwarden-config.conf`)
|
||||||
|
- **`-h, --help`** - Show help message
|
||||||
|
- **`-v, --version`** - Show version information
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install Bitwarden CLI
|
||||||
|
./secrets-manager.sh install
|
||||||
|
|
||||||
|
# Test your configuration
|
||||||
|
./secrets-manager.sh test
|
||||||
|
|
||||||
|
# Get a specific secret
|
||||||
|
./secrets-manager.sh get APIKEY-pushover
|
||||||
|
|
||||||
|
# List all available secrets
|
||||||
|
./secrets-manager.sh list
|
||||||
|
|
||||||
|
# Use a custom config file
|
||||||
|
./secrets-manager.sh --config /path/to/custom.conf get my-secret
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using in Scripts
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
# Example: Load API key into environment variable
|
||||||
|
export PUSHOVER_API="$(./secrets-manager.sh get APIKEY-pushover)"
|
||||||
|
|
||||||
|
# Use the secret in your application
|
||||||
|
curl -X POST "https://api.pushover.net/1/messages.json" \
|
||||||
|
-d "token=$PUSHOVER_API" \
|
||||||
|
-d "user=your_user_key" \
|
||||||
|
-d "message=Hello from TSYS!"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installation Methods
|
||||||
|
|
||||||
|
The script automatically tries multiple installation methods in order:
|
||||||
|
|
||||||
|
1. **NPM Global Package** (if npm is available)
|
||||||
|
2. **Direct Binary Download** (fallback method)
|
||||||
|
|
||||||
|
## Error Codes
|
||||||
|
|
||||||
|
| Code | Description |
|
||||||
|
|------|-------------|
|
||||||
|
| 10 | Configuration file not found |
|
||||||
|
| 20 | Bitwarden CLI not installed |
|
||||||
|
| 30 | Bitwarden CLI installation failed |
|
||||||
|
| 40 | Server configuration failed |
|
||||||
|
| 50 | Session/unlock failed |
|
||||||
|
| 60 | Secret not found |
|
||||||
|
| 70 | Login failed |
|
||||||
|
|
||||||
|
## Logging
|
||||||
|
|
||||||
|
All operations are logged to `/tmp/secrets-manager.sh.log` for debugging and audit purposes.
|
||||||
|
|
||||||
|
## Security Considerations
|
||||||
|
|
||||||
|
- Configuration files containing credentials are automatically gitignored
|
||||||
|
- Session tokens are properly cleaned up on script exit
|
||||||
|
- Master passwords are handled securely without shell history exposure
|
||||||
|
- All sensitive operations include proper error handling
|
||||||
|
|
||||||
|
## Legacy Scripts
|
||||||
|
|
||||||
|
## Repository Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
KNELSecretsManager/
|
||||||
|
├── secrets-manager.sh # Main secrets management script
|
||||||
|
├── README.md # This documentation
|
||||||
|
├── LICENSE # License information
|
||||||
|
├── Makefile # Build and test automation
|
||||||
|
├── .gitignore # Git ignore rules
|
||||||
|
├── bin/ # Legacy scripts and utilities
|
||||||
|
│ ├── poc.sh # Original proof of concept
|
||||||
|
│ └── prod.sh # ChatGPT-assisted production attempt
|
||||||
|
├── config/ # Configuration templates
|
||||||
|
│ └── bitwarden-config.conf.sample # Sample configuration
|
||||||
|
├── tests/ # Test suite
|
||||||
|
│ └── test-secrets-manager.sh # Comprehensive test framework
|
||||||
|
└── docs/ # Documentation
|
||||||
|
└── ADR-Node.md # Architecture Decision Records
|
||||||
|
```
|
||||||
|
|
||||||
|
The main `secrets-manager.sh` script combines the best features of the legacy implementations while adding robust error handling, installation management, and improved security.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
This project includes a comprehensive test suite designed to work both standalone and when vendored into shell scripting frameworks.
|
||||||
|
|
||||||
|
### Running Tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run all tests
|
||||||
|
./tests/test-secrets-manager.sh run
|
||||||
|
|
||||||
|
# Run tests in CI mode (no colors)
|
||||||
|
./tests/test-secrets-manager.sh --ci run
|
||||||
|
|
||||||
|
# Using Make (recommended)
|
||||||
|
make test # Run all tests
|
||||||
|
make test-ci # Run in CI mode
|
||||||
|
make lint # Run shellcheck
|
||||||
|
make all # Run deps, lint, and tests
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test Coverage
|
||||||
|
|
||||||
|
The test suite covers:
|
||||||
|
- Script existence and permissions
|
||||||
|
- Command-line argument parsing
|
||||||
|
- Help and version output
|
||||||
|
- Error handling and exit codes
|
||||||
|
- Configuration file validation
|
||||||
|
- Bitwarden CLI dependency checks
|
||||||
|
- Performance and startup time
|
||||||
|
- Vendor integration compatibility
|
||||||
|
|
||||||
|
### Vendor Integration Testing
|
||||||
|
|
||||||
|
When this project is vendored into other shell scripting frameworks:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Test as vendored dependency
|
||||||
|
make vendor-test
|
||||||
|
|
||||||
|
# Or manually
|
||||||
|
mkdir /tmp/vendor-test
|
||||||
|
cp secrets-manager.sh tests/test-secrets-manager.sh config/bitwarden-config.conf.sample /tmp/vendor-test/
|
||||||
|
cd /tmp/vendor-test && ./test-secrets-manager.sh --ci run
|
||||||
|
```
|
||||||
|
|
||||||
|
### Development Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Setup development environment
|
||||||
|
make dev-setup
|
||||||
|
|
||||||
|
# Run tests with development config
|
||||||
|
make dev-test
|
||||||
|
```
|
||||||
|
|
||||||
|
## Architecture Decision Records
|
||||||
|
|
||||||
|
This project includes ADRs for key architectural decisions:
|
||||||
|
|
||||||
|
- **ADR-001**: [Node.js Version Management Strategy](docs/ADR-Node.md) - Analysis of MISE vs system packages for Node.js version management
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
When contributing to this project:
|
||||||
|
|
||||||
|
1. **Test all changes thoroughly**:
|
||||||
|
```bash
|
||||||
|
make ci # Run full CI pipeline
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Update documentation as needed**
|
||||||
|
3. **Follow existing code style and conventions**
|
||||||
|
4. **Run security checks**:
|
||||||
|
```bash
|
||||||
|
make security-check
|
||||||
|
```
|
||||||
|
|
||||||
|
5. **Ensure compatibility with vendor integration**:
|
||||||
|
```bash
|
||||||
|
make vendor-test
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make help # Show all available commands
|
||||||
|
make install # Install dependencies
|
||||||
|
make dev-setup # Setup development environment
|
||||||
|
make lint # Run shellcheck
|
||||||
|
make security-check # Basic security validation
|
||||||
|
make clean # Clean temporary files
|
||||||
|
make docs # Generate documentation
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
See [LICENSE](LICENSE) file for details.
|
||||||
Executable
+75
@@ -0,0 +1,75 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# bw-cli.sh — Bitwarden CLI host wrapper (container-based, native Rust binary).
|
||||||
|
#
|
||||||
|
# Provides transparent `bw` access on hosts where the CLI is not installed
|
||||||
|
# natively. Runs the pre-compiled Rust bw binary inside a minimal Docker
|
||||||
|
# container (debian-slim + ca-certificates, NO Node.js).
|
||||||
|
#
|
||||||
|
# All tool execution happens inside the container. Nothing runs on the host
|
||||||
|
# except this wrapper, which only invokes docker.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# bw-cli.sh status Check vault status
|
||||||
|
# bw-cli.sh list items List vault items
|
||||||
|
# bw-cli.sh list collections List collections
|
||||||
|
# bw-cli.sh get password "Item" Retrieve a password
|
||||||
|
# bw-cli.sh get totp "Item" Retrieve a TOTP code
|
||||||
|
# bw-cli.sh get item "Item" Full item JSON
|
||||||
|
# bw-cli.sh generate -ulns Generate a password
|
||||||
|
#
|
||||||
|
# Install to ~/.local/bin/bw via:
|
||||||
|
# scripts/bw-install.sh
|
||||||
|
#
|
||||||
|
# Environment overrides:
|
||||||
|
# BW_ENV_FILE Path to credentials (default: ~/.config/bw/env)
|
||||||
|
# BW_IMAGE Docker image (default: reachableceo-bw-native:2026.7.0)
|
||||||
|
# BW_VOLUME Docker volume for persisted login state
|
||||||
|
# (default: tsys-bw-cli-state)
|
||||||
|
# BW_LIB_DIR Directory containing entrypoint.sh (default: ~/.local/share/bw)
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
BW_ENV_FILE="${BW_ENV_FILE:-$HOME/.config/bw/env}"
|
||||||
|
BW_IMAGE="${BW_IMAGE:-reachableceo-bw-native:2026.7.0}"
|
||||||
|
BW_VOLUME="${BW_VOLUME:-tsys-bw-cli-state}"
|
||||||
|
BW_LIB_DIR="${BW_LIB_DIR:-$HOME/.local/share/bw}"
|
||||||
|
|
||||||
|
# --- Validate prerequisites ---
|
||||||
|
if [ ! -f "$BW_ENV_FILE" ]; then
|
||||||
|
echo "bw: credential file not found: $BW_ENV_FILE" >&2
|
||||||
|
echo " expected BW_CLIENTID, BW_CLIENTSECRET, BW_PASSWORD, BW_SERVER" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! docker image inspect "$BW_IMAGE" >/dev/null 2>&1; then
|
||||||
|
echo "bw: Docker image not found: $BW_IMAGE" >&2
|
||||||
|
echo " build it: scripts/bw-install.sh" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$BW_LIB_DIR/entrypoint.sh" ]; then
|
||||||
|
echo "bw: entrypoint script missing: $BW_LIB_DIR/entrypoint.sh" >&2
|
||||||
|
echo " install via: scripts/bw-install.sh" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Load credentials (values are single-quoted in env file) ---
|
||||||
|
set -a
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$BW_ENV_FILE"
|
||||||
|
set +a
|
||||||
|
|
||||||
|
# --- Create persistent volume for BW CLI login state ---
|
||||||
|
docker volume create "$BW_VOLUME" >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
# --- Run bw inside the container ---
|
||||||
|
docker run --rm -i \
|
||||||
|
-e BW_CLIENTID \
|
||||||
|
-e BW_CLIENTSECRET \
|
||||||
|
-e BW_PASSWORD \
|
||||||
|
-e BW_SERVER \
|
||||||
|
-v "$BW_VOLUME:/root/.config/Bitwarden CLI" \
|
||||||
|
-v "$BW_LIB_DIR/entrypoint.sh:/opt/bw/entrypoint.sh:ro" \
|
||||||
|
--entrypoint sh \
|
||||||
|
"$BW_IMAGE" \
|
||||||
|
/opt/bw/entrypoint.sh "$@"
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# bw-entrypoint.sh — Bitwarden auth lifecycle, runs inside the container.
|
||||||
|
#
|
||||||
|
# Mounted at /opt/bw/entrypoint.sh by the host-side wrapper (bw-cli.sh).
|
||||||
|
# Handles: server config, API-key login, vault unlock, sync.
|
||||||
|
# Then execs the real bw command with BW_SESSION set.
|
||||||
|
#
|
||||||
|
# API key authentication does NOT require TOTP. The API key itself is
|
||||||
|
# obtained from an authenticated web vault session, so 2FA is already
|
||||||
|
# satisfied at key-generation time.
|
||||||
|
#
|
||||||
|
# This script intentionally uses /bin/sh (not bash) for minimal container
|
||||||
|
# compatibility. shellcheck directive below silences the "not bash" note.
|
||||||
|
# shellcheck shell=sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
BW_SERVER="${BW_SERVER:-https://pwvault.turnsys.com}"
|
||||||
|
|
||||||
|
# Suppress BW CLI data-dir creation noise and telemetry.
|
||||||
|
export BW_NO_SENTRY=true
|
||||||
|
|
||||||
|
# --- Step 1: Configure server (fails harmlessly if already logged in) ---
|
||||||
|
bw config server "$BW_SERVER" >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
# --- Step 2: Login via API key (silently skips if already authenticated) ---
|
||||||
|
bw login --apikey >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
# --- Step 3: Unlock the vault ---
|
||||||
|
printf '%s' "$BW_PASSWORD" > /tmp/.bwpw
|
||||||
|
SESS=$(bw unlock --passwordfile /tmp/.bwpw --raw 2>/dev/null)
|
||||||
|
rm -f /tmp/.bwpw
|
||||||
|
if [ -z "$SESS" ]; then
|
||||||
|
echo "bw: unlock failed. Check BW_PASSWORD in ~/.config/bw/env" >&2
|
||||||
|
echo " Values must be single-quoted; \$ chars get mangled if unquoted." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Step 4: Sync ---
|
||||||
|
bw sync --session "$SESS" >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
# --- Step 5: Execute the requested command ---
|
||||||
|
export BW_SESSION="$SESS"
|
||||||
|
exec bw "$@"
|
||||||
Executable
+125
@@ -0,0 +1,125 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# bw-install.sh — Install the container-based Bitwarden CLI wrapper.
|
||||||
|
#
|
||||||
|
# Downloads the native Rust bw binary, builds the Docker image, and installs
|
||||||
|
# the host-side wrapper plus container entrypoint to the user's local paths.
|
||||||
|
# No Node.js is involved at any layer.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# bw-install.sh Download, build, and install everything
|
||||||
|
# bw-install.sh --check Verify installation status without changes
|
||||||
|
#
|
||||||
|
# Prerequisites:
|
||||||
|
# - docker on PATH
|
||||||
|
# - BW env file at ~/.config/bw/env (see prereq-check.sh in TSYSGroupAIOS)
|
||||||
|
#
|
||||||
|
# After install, ~/.local/bin/bw provides transparent CLI access. Add
|
||||||
|
# ~/.local/bin to PATH if not already (most distros do this via ~/.profile).
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
REPO_ROOT="$(cd "$HERE/.." && pwd)"
|
||||||
|
|
||||||
|
BW_VERSION="2026.7.0"
|
||||||
|
BW_IMAGE="reachableceo-bw-native:${BW_VERSION}"
|
||||||
|
BW_BINARY_URL="https://github.com/bitwarden/clients/releases/download/cli-v${BW_VERSION}/bw-linux-${BW_VERSION}.zip"
|
||||||
|
|
||||||
|
INSTALL_BIN="${HOME}/.local/bin"
|
||||||
|
INSTALL_LIB="${HOME}/.local/share/bw"
|
||||||
|
BUILD_DIR=""
|
||||||
|
|
||||||
|
# --- Helpers ---
|
||||||
|
log_info() { printf '\033[0;34m›\033[0m %s\n' "$*"; }
|
||||||
|
log_ok() { printf '\033[0;32m✓\033[0m %s\n' "$*"; }
|
||||||
|
log_warn() { printf '\033[1;33m⚠\033[0m %s\n' "$*" >&2; }
|
||||||
|
log_error() { printf '\033[0;31m✗\033[0m %s\n' "$*" >&2; }
|
||||||
|
log_step() { printf '\n\033[1m== %s ==\033[0m\n' "$*"; }
|
||||||
|
die() { log_error "$*"; exit 1; }
|
||||||
|
|
||||||
|
# --- Cleanup on exit ---
|
||||||
|
cleanup() {
|
||||||
|
[ -n "$BUILD_DIR" ] && rm -rf "$BUILD_DIR"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
# --- Check mode ---
|
||||||
|
if [ "${1:-}" = "--check" ]; then
|
||||||
|
log_step "BW CLI installation check"
|
||||||
|
if command -v docker >/dev/null 2>&1; then
|
||||||
|
log_ok "docker on PATH"
|
||||||
|
else
|
||||||
|
log_error "docker not on PATH"
|
||||||
|
fi
|
||||||
|
if docker image inspect "$BW_IMAGE" >/dev/null 2>&1; then
|
||||||
|
log_ok "Docker image ${BW_IMAGE} exists"
|
||||||
|
else
|
||||||
|
log_error "Docker image ${BW_IMAGE} missing"
|
||||||
|
fi
|
||||||
|
if [ -x "${INSTALL_BIN}/bw" ]; then
|
||||||
|
log_ok "Host wrapper at ${INSTALL_BIN}/bw"
|
||||||
|
else
|
||||||
|
log_error "Host wrapper at ${INSTALL_BIN}/bw missing"
|
||||||
|
fi
|
||||||
|
if [ -f "${INSTALL_LIB}/entrypoint.sh" ]; then
|
||||||
|
log_ok "Entrypoint at ${INSTALL_LIB}/entrypoint.sh"
|
||||||
|
else
|
||||||
|
log_error "Entrypoint at ${INSTALL_LIB}/entrypoint.sh missing"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Prerequisites ---
|
||||||
|
command -v docker >/dev/null 2>&1 || die "docker not found on PATH"
|
||||||
|
|
||||||
|
log_step "Installing container-based Bitwarden CLI (native Rust, no Node.js)"
|
||||||
|
|
||||||
|
# --- Step 1: Download and extract the native binary ---
|
||||||
|
BUILD_DIR=$(mktemp -d)
|
||||||
|
log_info "Downloading bw ${BW_VERSION} native binary..."
|
||||||
|
|
||||||
|
docker run --rm -v "${BUILD_DIR}:/build" alpine:3.20 \
|
||||||
|
sh -c "apk add --no-cache unzip >/dev/null 2>&1 && \
|
||||||
|
wget -q -O /build/bw.zip '${BW_BINARY_URL}' && \
|
||||||
|
unzip -o /build/bw.zip -d /build/ && \
|
||||||
|
rm /build/bw.zip && \
|
||||||
|
chmod +x /build/bw"
|
||||||
|
|
||||||
|
[ -f "${BUILD_DIR}/bw" ] || die "download failed: bw binary not found"
|
||||||
|
log_ok "Downloaded native binary"
|
||||||
|
|
||||||
|
# --- Step 2: Build the Docker image ---
|
||||||
|
log_info "Building Docker image ${BW_IMAGE}..."
|
||||||
|
|
||||||
|
DOCKERFILE_DIR="${REPO_ROOT}/docker/bw-native"
|
||||||
|
if [ ! -f "${DOCKERFILE_DIR}/Dockerfile" ]; then
|
||||||
|
die "Dockerfile not found: ${DOCKERFILE_DIR}/Dockerfile"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp "${BUILD_DIR}/bw" "${DOCKERFILE_DIR}/bw"
|
||||||
|
docker build -t "$BW_IMAGE" "$DOCKERFILE_DIR"
|
||||||
|
rm -f "${DOCKERFILE_DIR}/bw"
|
||||||
|
log_ok "Built image ${BW_IMAGE}"
|
||||||
|
|
||||||
|
# --- Step 3: Install host-side wrapper and entrypoint ---
|
||||||
|
mkdir -p "$INSTALL_BIN" "$INSTALL_LIB"
|
||||||
|
|
||||||
|
cp "${HERE}/bw-cli.sh" "${INSTALL_BIN}/bw"
|
||||||
|
chmod 755 "${INSTALL_BIN}/bw"
|
||||||
|
log_ok "Installed wrapper to ${INSTALL_BIN}/bw"
|
||||||
|
|
||||||
|
cp "${HERE}/bw-entrypoint.sh" "${INSTALL_LIB}/entrypoint.sh"
|
||||||
|
chmod 755 "${INSTALL_LIB}/entrypoint.sh"
|
||||||
|
log_ok "Installed entrypoint to ${INSTALL_LIB}/entrypoint.sh"
|
||||||
|
|
||||||
|
# --- Step 4: Verify ---
|
||||||
|
log_info "Verifying installation..."
|
||||||
|
if "${INSTALL_BIN}/bw" --version >/dev/null 2>&1; then
|
||||||
|
log_ok "bw CLI is operational"
|
||||||
|
else
|
||||||
|
log_warn "bw wrapper installed but verification call failed"
|
||||||
|
log_warn "check ~/.config/bw/env credentials and try: bw status"
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_step "Installation complete"
|
||||||
|
log_info "Usage: bw status | bw list items | bw get password \"Item Name\""
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# A quick and dirty proof of concept to capture bitwarden cli workflow
|
||||||
|
# A reduction to practice of the data From https://bitwarden.com/help/cli/
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
|
####################################
|
||||||
|
## Step 0: Set to use tsys server
|
||||||
|
####################################
|
||||||
|
echo "Setting cli to use tsys bitwarden server..."
|
||||||
|
|
||||||
|
bw config server https://pwvault.turnsys.com
|
||||||
|
|
||||||
|
####################################
|
||||||
|
## Step 1: login to bitwarden
|
||||||
|
####################################
|
||||||
|
|
||||||
|
# From: https://bitwarden.com/help/cli/#using-an-api-key
|
||||||
|
|
||||||
|
### Set apikey environment varaible
|
||||||
|
|
||||||
|
echo "Sourcing clientid/apikey data..."
|
||||||
|
source D:/tsys/secrets/bitwarden/data/apikey-bitwarden-reachableceo
|
||||||
|
|
||||||
|
### Login to vault using apikey...
|
||||||
|
|
||||||
|
echo "Logging in..."
|
||||||
|
bw login --apikey $BW_CLIENTID $BW_CLIENTSECRET
|
||||||
|
|
||||||
|
### Step 1.1: unlock / save session id
|
||||||
|
|
||||||
|
echo "Unlocking..."
|
||||||
|
export BW_SESSION="$(bw unlock --passwordenv TSYS_BW_PASSWORD_REACHABLECEO --raw)"
|
||||||
|
|
||||||
|
|
||||||
|
### Step 2: retrive a value into an environment variable
|
||||||
|
|
||||||
|
export PUSHOVER_APIKEY="$(bw get password APIKEY-pushover)"
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Written by Chatgpt
|
||||||
|
# 70% problem for sure..
|
||||||
|
|
||||||
|
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
|
||||||
|
# Bash3 Boilerplate Setup
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
# Constants
|
||||||
|
readonly SCRIPT_NAME=$(basename "$0")
|
||||||
|
readonly SCRIPT_VERSION="1.0"
|
||||||
|
readonly SCRIPT_AUTHOR="Charles N Wyble"
|
||||||
|
readonly SCRIPT_DESC="TSYS Secrets Manager - Fetch secrets using the Bitwarden CLI"
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
readonly BW_SERVER_URL="https://pwvault.turnsys.com" # Updated Bitwarden server URL
|
||||||
|
|
||||||
|
# Logging and Debugging
|
||||||
|
readonly LOG_FILE="/tmp/${SCRIPT_NAME}.log"
|
||||||
|
readonly TIMESTAMP=$(date '+%m-%d-%Y %H:%M:%S')
|
||||||
|
info() { echo "[INFO] [$TIMESTAMP] $*" | tee -a "$LOG_FILE"; }
|
||||||
|
error() { echo "[ERROR] [$TIMESTAMP] $*" >&2 | tee -a "$LOG_FILE"; }
|
||||||
|
|
||||||
|
# Default Exit Codes
|
||||||
|
readonly ERR_BW_NOT_INSTALLED=10
|
||||||
|
readonly ERR_BW_SERVER_CONFIG=20
|
||||||
|
readonly ERR_SESSION_INVALID=30
|
||||||
|
readonly ERR_SECRET_NOT_FOUND=40
|
||||||
|
|
||||||
|
# Cleanup function to unset session environment variable
|
||||||
|
cleanup() {
|
||||||
|
info "Cleaning up and unsetting session environment variable."
|
||||||
|
unset BW_SESSION
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: Setup Bitwarden server configuration
|
||||||
|
setup_bitwarden_server() {
|
||||||
|
info "Configuring Bitwarden server to $BW_SERVER_URL..."
|
||||||
|
# Set the server URL for Bitwarden CLI
|
||||||
|
if ! bw config --quiet server "$BW_SERVER_URL"; then
|
||||||
|
error "Failed to configure Bitwarden server."
|
||||||
|
exit $ERR_BW_SERVER_CONFIG
|
||||||
|
fi
|
||||||
|
info "Bitwarden server configured successfully."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: Fetch or initialize Bitwarden session
|
||||||
|
fetch_bw_session() {
|
||||||
|
local session_token
|
||||||
|
|
||||||
|
# Check if Bitwarden CLI is installed
|
||||||
|
if ! command -v bw &>/dev/null; then
|
||||||
|
error "Bitwarden CLI (bw) is not installed or not in PATH. Please install it and try again."
|
||||||
|
exit $ERR_BW_NOT_INSTALLED
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for existing session environment variable and reuse if valid
|
||||||
|
if [[ -n "${BW_SESSION:-}" ]] && bw unlock --check --session "$BW_SESSION" >/dev/null 2>&1; then
|
||||||
|
info "Using existing Bitwarden session token."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Unlock the Bitwarden vault and obtain a new session token
|
||||||
|
info "Unlocking Bitwarden vault..."
|
||||||
|
|
||||||
|
bw login --apikey $BW_CLIENTID $BW_CLIENTSECRET
|
||||||
|
|
||||||
|
session_token=$(bw unlock --passwordenv TSYS_BW_PASSWORD_REACHABLECEO --raw)
|
||||||
|
if [[ -z "$session_token" ]]; then
|
||||||
|
error "Failed to unlock Bitwarden vault. Ensure you're logged in using 'bw login'."
|
||||||
|
exit $ERR_SESSION_INVALID
|
||||||
|
fi
|
||||||
|
|
||||||
|
export BW_SESSION="$session_token"
|
||||||
|
info "Session initialized successfully."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: Fetch a secret by name
|
||||||
|
fetch_secret() {
|
||||||
|
local secret_name="$1"
|
||||||
|
local secret_value
|
||||||
|
|
||||||
|
info "Fetching secret '$secret_name' from Bitwarden..."
|
||||||
|
if ! secret_value=$(bw get password "$secret_name" --session "$BW_SESSION"); then
|
||||||
|
error "Failed to retrieve the secret '$secret_name'. Ensure the secret exists in the vault."
|
||||||
|
exit $ERR_SECRET_NOT_FOUND
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$secret_value" ]]; then
|
||||||
|
error "Secret '$secret_name' is empty or not found. Check the vault for proper configuration."
|
||||||
|
exit $ERR_SECRET_NOT_FOUND
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function: Display usage instructions
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
$SCRIPT_DESC
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
$SCRIPT_NAME <secret_name>
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help Display this help message.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
$SCRIPT_NAME tsys_api_key
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main function
|
||||||
|
main() {
|
||||||
|
|
||||||
|
bw logout || true
|
||||||
|
|
||||||
|
source D:/tsys/secrets/bitwarden/data/apikey-bitwarden-reachableceo
|
||||||
|
|
||||||
|
local secret_name="$1"
|
||||||
|
|
||||||
|
# Setup Bitwarden server and session management
|
||||||
|
setup_bitwarden_server
|
||||||
|
fetch_bw_session
|
||||||
|
|
||||||
|
# Fetch the specified secret
|
||||||
|
secret_value=$(fetch_secret "$secret_name")
|
||||||
|
info "Secret '$secret_name' fetched successfully."
|
||||||
|
|
||||||
|
echo "Secret value is: $secret_value"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Trap signals (Ctrl+C, kill, etc.) to ensure cleanup happens
|
||||||
|
trap cleanup EXIT INT TERM
|
||||||
|
|
||||||
|
# Argument parsing
|
||||||
|
if [[ $# -lt 1 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
main "$1"
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# Bitwarden Configuration File
|
||||||
|
# Copy this file to bitwarden-config.conf and update with your actual values
|
||||||
|
|
||||||
|
# Bitwarden server URL
|
||||||
|
BW_SERVER_URL="https://pwvault.turnsys.com"
|
||||||
|
|
||||||
|
# API credentials (get these from your Bitwarden account settings)
|
||||||
|
BW_CLIENTID="your_client_id_here"
|
||||||
|
BW_CLIENTSECRET="your_client_secret_here"
|
||||||
|
|
||||||
|
# Master password for your Bitwarden account
|
||||||
|
BW_PASSWORD="your_master_password_here"
|
||||||
|
|
||||||
|
# Optional: Additional environment variables
|
||||||
|
# BW_ORGANIZATION_ID="your_org_id_here"
|
||||||
|
# BW_COLLECTION_ID="your_collection_id_here"
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# Dockerfile — Native Bitwarden CLI (Rust binary, no Node.js)
|
||||||
|
#
|
||||||
|
# Builds a minimal container image around the pre-compiled native bw CLI
|
||||||
|
# binary from the official Bitwarden GitHub releases. The binary is a
|
||||||
|
# Rust executable with glibc dependencies. No Node.js runtime is
|
||||||
|
# included or required.
|
||||||
|
#
|
||||||
|
# Build prerequisites:
|
||||||
|
# 1. Download the native binary:
|
||||||
|
# https://github.com/bitwarden/clients/releases/download/cli-v2026.7.0/bw-linux-2026.7.0.zip
|
||||||
|
# 2. Unzip and place the `bw` executable next to this Dockerfile.
|
||||||
|
# 3. Build: docker build -t reachableceo-bw-native:2026.7.0 .
|
||||||
|
#
|
||||||
|
# Or use the installer: scripts/bw-install.sh
|
||||||
|
|
||||||
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY bw /usr/local/bin/bw
|
||||||
|
RUN chmod +x /usr/local/bin/bw
|
||||||
|
|
||||||
|
ENTRYPOINT ["bw"]
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
# ADR-002: Container-Based Bitwarden CLI (No Host Node.js)
|
||||||
|
|
||||||
|
## Status
|
||||||
|
|
||||||
|
Accepted (supersedes ADR-001 for BW CLI purposes)
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
ADR-001 selected a hybrid Node.js version-management strategy because the
|
||||||
|
Bitwarden CLI (`bw`) is distributed via npm and therefore requires a Node.js
|
||||||
|
runtime on every consuming host. For TSYS hosts operating under CMMC L3 /
|
||||||
|
ITAR / STIG alignment, any host-side language runtime is an attack surface
|
||||||
|
and a compliance finding. The KNEL/TSYS baseline ("Docker for everything")
|
||||||
|
also forbids host language toolchains.
|
||||||
|
|
||||||
|
Bitwarden additionally publishes the CLI as a pre-compiled single binary.
|
||||||
|
Distributing that binary inside a minimal pinned container gives every host
|
||||||
|
transparent `bw` access with zero host-side runtimes.
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
**Run the official pre-compiled bw binary inside a pinned Docker container,
|
||||||
|
exposed to users as a transparent `bw` wrapper at `~/.local/bin/bw`.**
|
||||||
|
|
||||||
|
Components (all in this repo):
|
||||||
|
|
||||||
|
| File | Role |
|
||||||
|
|---|---|
|
||||||
|
| `docker/bw-native/Dockerfile` | `debian:12-slim` + ca-certificates + bw binary, pinned `2026.7.0` |
|
||||||
|
| `bin/bw-entrypoint.sh` | In-container auth lifecycle: config server, API-key login, unlock, sync, exec |
|
||||||
|
| `bin/bw-cli.sh` | Host wrapper: docker run with volume-persisted session, tsys- container prefix |
|
||||||
|
| `bin/bw-install.sh` | One-command installer for the wrapper + image |
|
||||||
|
|
||||||
|
Credentials live only in `~/.config/bw/env` (single-quoted values, mode 600)
|
||||||
|
per the org-wide "no secrets on disk except BW access info" rule. The
|
||||||
|
Vaultwarden API key is used for login (no TOTP interaction needed); the
|
||||||
|
master password unlocks the vault; `bw sync` runs after every login so
|
||||||
|
multi-client vault state stays coherent.
|
||||||
|
|
||||||
|
## Known Caveat
|
||||||
|
|
||||||
|
The Bitwarden "native" Linux binary is actually a Node.js SEA (Single
|
||||||
|
Executable Application): it embeds a Node.js runtime and can print Node
|
||||||
|
errors on crash. Node.js is **absent from every host**, which satisfies the
|
||||||
|
host-hygiene goal, but the "zero Node.js anywhere" stretch goal is not met.
|
||||||
|
Alternatives (Rust vaultwarden clients such as `rbw`) were considered and
|
||||||
|
rejected for now due to Vaultwarden API compatibility gaps. Revisit if a
|
||||||
|
mature Rust client emerges; the wrapper isolates users from this swap.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
### Positive
|
||||||
|
|
||||||
|
- Zero language runtimes on hosts (CMMC/ITAR/STIG-friendly host hygiene)
|
||||||
|
- Identical bw behavior across all TSYS hosts; version pinned in one Dockerfile
|
||||||
|
- Session persistence via named Docker volume; no state divergence when
|
||||||
|
wrapper is used consistently
|
||||||
|
- Vendoring into shell frameworks is one installer invocation
|
||||||
|
|
||||||
|
### Negative
|
||||||
|
|
||||||
|
- Requires Docker on every consuming host (accepted: it is an org baseline)
|
||||||
|
- SEA caveat above (Node embedded inside the container image)
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
Deployed and verified on the TSGCOO orchestration host against
|
||||||
|
`https://pwvault.turnsys.com` (account `coo@turnsys.com`): status, list,
|
||||||
|
generate, get password/totp/item, create/edit items. Shellcheck clean at
|
||||||
|
zero warnings including info-level. In production use since 2026-08-13.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Decision Date:** 2026-08-14
|
||||||
|
**Decision Makers:** VP TechOps (proposed), TSGCOO (implemented)
|
||||||
|
**Related:** ADR-001 (superseded for BW CLI purposes; MISE guidance remains
|
||||||
|
valid for projects that genuinely require host Node.js)
|
||||||
@@ -0,0 +1,212 @@
|
|||||||
|
# ADR-001: Node.js Version Management Strategy
|
||||||
|
|
||||||
|
## Status
|
||||||
|
Proposed
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
The TSYS Secrets Manager project needs to make an architectural decision regarding Node.js version management across development, staging, and production environments. This decision impacts:
|
||||||
|
|
||||||
|
- Development workflow and environment consistency
|
||||||
|
- Production stability and security posture
|
||||||
|
- Operational complexity and maintenance overhead
|
||||||
|
- Compliance with enterprise security policies
|
||||||
|
- Integration with existing shell scripting frameworks
|
||||||
|
|
||||||
|
As this project will be git vendor included into shell scripting frameworks, the Node.js management approach must be portable and not introduce complex dependencies on the consuming systems.
|
||||||
|
|
||||||
|
## Decision Drivers
|
||||||
|
|
||||||
|
1. **Security and Compliance**: Enterprise security requirements mandate automated security updates and clear audit trails
|
||||||
|
2. **Operational Simplicity**: Minimize operational overhead and complexity in production environments
|
||||||
|
3. **Development Efficiency**: Enable developers to work with appropriate Node.js versions for different projects
|
||||||
|
4. **Vendor Integration**: Support clean integration when vendored into other shell scripting frameworks
|
||||||
|
5. **Stability**: Ensure production deployments are stable and predictable
|
||||||
|
6. **Version Flexibility**: Ability to test and deploy with specific Node.js versions when needed
|
||||||
|
|
||||||
|
## Options Considered
|
||||||
|
|
||||||
|
### Option 1: MISE (Modern Infrastructure Software Engineering)
|
||||||
|
**Description**: Use MISE for polyglot runtime version management across all environments.
|
||||||
|
|
||||||
|
**Pros**:
|
||||||
|
- Zero-overhead performance (no shims, direct binary execution)
|
||||||
|
- Multi-version support with automatic project-based switching
|
||||||
|
- Modern Rust-based implementation with enhanced security
|
||||||
|
- Excellent developer experience with unified tooling
|
||||||
|
- Support for `.nvmrc` and other standard version files
|
||||||
|
- Task runner capabilities
|
||||||
|
|
||||||
|
**Cons**:
|
||||||
|
- Additional operational complexity in production
|
||||||
|
- Custom security update processes required
|
||||||
|
- Not managed by distribution security teams
|
||||||
|
- Requires team training and adoption
|
||||||
|
- May complicate vendor integration scenarios
|
||||||
|
|
||||||
|
### Option 2: System Package Manager (Debian apt)
|
||||||
|
**Description**: Use distribution-provided Node.js packages for all environments.
|
||||||
|
|
||||||
|
**Pros**:
|
||||||
|
- Managed by Debian security team with automatic updates
|
||||||
|
- Battle-tested in enterprise environments
|
||||||
|
- Integration with existing configuration management
|
||||||
|
- Clear audit trails and compliance support
|
||||||
|
- Minimal operational overhead
|
||||||
|
- Standard enterprise security practices
|
||||||
|
|
||||||
|
**Cons**:
|
||||||
|
- Often outdated versions (significant lag behind releases)
|
||||||
|
- Limited to single system-wide version
|
||||||
|
- Cannot easily test multiple Node.js versions
|
||||||
|
- May not support latest language features
|
||||||
|
- Difficulty matching exact versions across environments
|
||||||
|
|
||||||
|
### Option 3: Containerized Deployment with Official Images
|
||||||
|
**Description**: Use official Node.js Docker images with pinned versions.
|
||||||
|
|
||||||
|
**Pros**:
|
||||||
|
- Reproducible deployments with exact version control
|
||||||
|
- Security scanning and automated vulnerability management
|
||||||
|
- Isolation from host system dependencies
|
||||||
|
- Industry standard approach for modern deployments
|
||||||
|
- Easy version management through Dockerfile
|
||||||
|
|
||||||
|
**Cons**:
|
||||||
|
- Requires container orchestration infrastructure
|
||||||
|
- Additional complexity for simple script deployments
|
||||||
|
- May be overkill for shell script frameworks
|
||||||
|
- Learning curve for container-naive environments
|
||||||
|
|
||||||
|
### Option 4: Hybrid Approach
|
||||||
|
**Description**: Use different tools for different environments and use cases.
|
||||||
|
|
||||||
|
**Pros**:
|
||||||
|
- Optimized approach for each environment's specific needs
|
||||||
|
- Flexibility to choose best tool for each scenario
|
||||||
|
- Can evolve strategy as requirements change
|
||||||
|
|
||||||
|
**Cons**:
|
||||||
|
- Increased complexity managing multiple approaches
|
||||||
|
- Potential for environment drift and inconsistencies
|
||||||
|
- More documentation and training required
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
**Selected: Option 4 - Hybrid Approach with System Packages as Primary**
|
||||||
|
|
||||||
|
### Primary Strategy:
|
||||||
|
- **Production Environments**: Use Debian system packages (apt) for Node.js installation
|
||||||
|
- **Development Environments**: Use MISE for flexibility and multi-version testing
|
||||||
|
- **Vendor Integration**: Document both approaches, default to system packages
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
1. **Security-First Production**: System packages provide the security posture required for enterprise production environments with automated security updates and established audit trails.
|
||||||
|
|
||||||
|
2. **Development Flexibility**: MISE enables developers to test across multiple Node.js versions and maintain development-production parity when needed.
|
||||||
|
|
||||||
|
3. **Vendor-Friendly**: When this project is vendored into shell scripting frameworks, defaulting to system packages minimizes external dependencies and complexity for consuming systems.
|
||||||
|
|
||||||
|
4. **Gradual Adoption**: Teams can start with system packages and adopt MISE for development as needed, without disrupting production systems.
|
||||||
|
|
||||||
|
## Implementation Guidelines
|
||||||
|
|
||||||
|
### For Production Deployments:
|
||||||
|
```bash
|
||||||
|
# Install Node.js via system package manager
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install nodejs npm
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
node --version
|
||||||
|
npm --version
|
||||||
|
```
|
||||||
|
|
||||||
|
### For Development Environments:
|
||||||
|
```bash
|
||||||
|
# Install MISE
|
||||||
|
curl https://mise.run | sh
|
||||||
|
|
||||||
|
# Configure for project
|
||||||
|
mise use node@18.17.0
|
||||||
|
mise use node@20.9.0 # For testing newer versions
|
||||||
|
|
||||||
|
# Project-specific configuration
|
||||||
|
echo "node 18.17.0" > .tool-versions
|
||||||
|
```
|
||||||
|
|
||||||
|
### For Vendor Integration:
|
||||||
|
- Default installation scripts should use system packages
|
||||||
|
- Provide optional MISE support for advanced users
|
||||||
|
- Document both approaches clearly
|
||||||
|
- Include version compatibility matrix
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
### Positive:
|
||||||
|
- Production systems maintain enterprise security standards
|
||||||
|
- Development teams gain version management flexibility
|
||||||
|
- Reduced vendor integration complexity
|
||||||
|
- Clear separation of concerns between environments
|
||||||
|
- Future migration paths remain open
|
||||||
|
|
||||||
|
### Negative:
|
||||||
|
- Increased documentation requirements
|
||||||
|
- Potential for environment drift if not managed properly
|
||||||
|
- Team training required for both approaches
|
||||||
|
- Slightly more complex CI/CD pipelines
|
||||||
|
|
||||||
|
### Neutral:
|
||||||
|
- Need to maintain compatibility with both package management approaches
|
||||||
|
- Version testing required across both installation methods
|
||||||
|
|
||||||
|
## Compliance and Security Considerations
|
||||||
|
|
||||||
|
### System Package Approach:
|
||||||
|
- Automatic security updates via `unattended-upgrades`
|
||||||
|
- Integration with enterprise vulnerability scanners
|
||||||
|
- Standard audit procedures apply
|
||||||
|
- Compliance with distribution security policies
|
||||||
|
|
||||||
|
### MISE Approach (Development Only):
|
||||||
|
- Manual security update processes
|
||||||
|
- Custom vulnerability monitoring required
|
||||||
|
- Developer responsibility for version management
|
||||||
|
- Clear policies needed for version selection
|
||||||
|
|
||||||
|
## Monitoring and Metrics
|
||||||
|
|
||||||
|
### Track:
|
||||||
|
- Node.js version distribution across environments
|
||||||
|
- Security update lag time between environments
|
||||||
|
- Developer adoption of MISE in development
|
||||||
|
- Issues related to version mismatches
|
||||||
|
|
||||||
|
### Success Criteria:
|
||||||
|
- Zero production security incidents related to Node.js versions
|
||||||
|
- <1 week lag time for critical security updates in production
|
||||||
|
- >90% developer satisfaction with version management workflow
|
||||||
|
- Successful vendor integrations with minimal friction
|
||||||
|
|
||||||
|
## Review Schedule
|
||||||
|
|
||||||
|
This ADR should be reviewed:
|
||||||
|
- Quarterly for the first year
|
||||||
|
- Annually thereafter
|
||||||
|
- When major Node.js LTS versions are released
|
||||||
|
- After significant security incidents
|
||||||
|
- When vendor integration patterns change
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [MISE Documentation](https://mise.jdx.dev/)
|
||||||
|
- [Node.js Release Schedule](https://nodejs.org/en/about/releases/)
|
||||||
|
- [Debian Node.js Packages](https://packages.debian.org/search?keywords=nodejs)
|
||||||
|
- [Enterprise Node.js Security Best Practices](https://nodejs.org/en/docs/guides/security/)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Decision Date**: 2025-07-16
|
||||||
|
**Decision Makers**: Architecture Team, Security Team, DevOps Team
|
||||||
|
**Next Review**: 2025-10-16
|
||||||
@@ -0,0 +1,283 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# TSYS Secrets Manager - Complete Bitwarden CLI management script
|
||||||
|
# Handles installation, configuration, authentication, and secret retrieval
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
readonly SCRIPT_NAME=$(basename "$0")
|
||||||
|
readonly SCRIPT_VERSION="2.0"
|
||||||
|
readonly SCRIPT_DESC="TSYS Secrets Manager - Complete Bitwarden CLI solution"
|
||||||
|
|
||||||
|
readonly DEFAULT_CONFIG_FILE="./bitwarden-config.conf"
|
||||||
|
readonly LOG_FILE="/tmp/${SCRIPT_NAME}.log"
|
||||||
|
readonly TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
info() { echo "[INFO] [$TIMESTAMP] $*" | tee -a "$LOG_FILE"; }
|
||||||
|
warn() { echo "[WARN] [$TIMESTAMP] $*" | tee -a "$LOG_FILE"; }
|
||||||
|
error() { echo "[ERROR] [$TIMESTAMP] $*" >&2 | tee -a "$LOG_FILE"; }
|
||||||
|
|
||||||
|
readonly ERR_CONFIG_NOT_FOUND=10
|
||||||
|
readonly ERR_BW_NOT_INSTALLED=20
|
||||||
|
readonly ERR_BW_INSTALL_FAILED=30
|
||||||
|
readonly ERR_BW_SERVER_CONFIG=40
|
||||||
|
readonly ERR_SESSION_INVALID=50
|
||||||
|
readonly ERR_SECRET_NOT_FOUND=60
|
||||||
|
readonly ERR_LOGIN_FAILED=70
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
info "Cleaning up session data..."
|
||||||
|
unset BW_SESSION 2>/dev/null || true
|
||||||
|
}
|
||||||
|
|
||||||
|
install_bitwarden_cli() {
|
||||||
|
info "Checking if Bitwarden CLI is installed..."
|
||||||
|
|
||||||
|
if command -v bw &>/dev/null; then
|
||||||
|
local version=$(bw --version)
|
||||||
|
info "Bitwarden CLI already installed: $version"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "Installing Bitwarden CLI..."
|
||||||
|
|
||||||
|
if command -v npm &>/dev/null; then
|
||||||
|
info "Installing via npm..."
|
||||||
|
if sudo npm install -g @bitwarden/cli; then
|
||||||
|
info "Bitwarden CLI installed successfully via npm"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "Installing via direct download..."
|
||||||
|
local bw_url="https://github.com/bitwarden/clients/releases/latest/download/bw-linux-1.22.1.zip"
|
||||||
|
local temp_dir=$(mktemp -d)
|
||||||
|
|
||||||
|
if command -v wget &>/dev/null; then
|
||||||
|
wget -O "$temp_dir/bw.zip" "$bw_url"
|
||||||
|
elif command -v curl &>/dev/null; then
|
||||||
|
curl -L -o "$temp_dir/bw.zip" "$bw_url"
|
||||||
|
else
|
||||||
|
error "Neither wget nor curl available for download"
|
||||||
|
exit $ERR_BW_INSTALL_FAILED
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v unzip &>/dev/null; then
|
||||||
|
unzip "$temp_dir/bw.zip" -d "$temp_dir"
|
||||||
|
sudo mv "$temp_dir/bw" /usr/local/bin/
|
||||||
|
sudo chmod +x /usr/local/bin/bw
|
||||||
|
rm -rf "$temp_dir"
|
||||||
|
info "Bitwarden CLI installed successfully via direct download"
|
||||||
|
else
|
||||||
|
error "unzip not available to extract Bitwarden CLI"
|
||||||
|
exit $ERR_BW_INSTALL_FAILED
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
load_config() {
|
||||||
|
local config_file="${1:-$DEFAULT_CONFIG_FILE}"
|
||||||
|
|
||||||
|
if [[ ! -f "$config_file" ]]; then
|
||||||
|
error "Configuration file not found: $config_file"
|
||||||
|
error "Please create a configuration file or use --config option"
|
||||||
|
exit $ERR_CONFIG_NOT_FOUND
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "Loading configuration from: $config_file"
|
||||||
|
source "$config_file"
|
||||||
|
|
||||||
|
if [[ -z "${BW_SERVER_URL:-}" ]]; then
|
||||||
|
error "BW_SERVER_URL not defined in config file"
|
||||||
|
exit $ERR_CONFIG_NOT_FOUND
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${BW_CLIENTID:-}" ]] || [[ -z "${BW_CLIENTSECRET:-}" ]]; then
|
||||||
|
error "BW_CLIENTID and BW_CLIENTSECRET must be defined in config file"
|
||||||
|
exit $ERR_CONFIG_NOT_FOUND
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${BW_PASSWORD:-}" ]]; then
|
||||||
|
error "BW_PASSWORD must be defined in config file"
|
||||||
|
exit $ERR_CONFIG_NOT_FOUND
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_bitwarden_server() {
|
||||||
|
info "Configuring Bitwarden server to $BW_SERVER_URL..."
|
||||||
|
|
||||||
|
if ! bw config server "$BW_SERVER_URL" >/dev/null 2>&1; then
|
||||||
|
error "Failed to configure Bitwarden server"
|
||||||
|
exit $ERR_BW_SERVER_CONFIG
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "Bitwarden server configured successfully"
|
||||||
|
}
|
||||||
|
|
||||||
|
login_and_unlock() {
|
||||||
|
info "Logging out any existing session..."
|
||||||
|
bw logout >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
info "Logging in with API key..."
|
||||||
|
if ! bw login --apikey "$BW_CLIENTID" "$BW_CLIENTSECRET" >/dev/null 2>&1; then
|
||||||
|
error "Failed to login with API key"
|
||||||
|
exit $ERR_LOGIN_FAILED
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "Unlocking vault..."
|
||||||
|
local session_token
|
||||||
|
session_token=$(echo "$BW_PASSWORD" | bw unlock --raw 2>/dev/null)
|
||||||
|
|
||||||
|
if [[ -z "$session_token" ]]; then
|
||||||
|
error "Failed to unlock vault with provided password"
|
||||||
|
exit $ERR_SESSION_INVALID
|
||||||
|
fi
|
||||||
|
|
||||||
|
export BW_SESSION="$session_token"
|
||||||
|
info "Vault unlocked successfully"
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch_secret() {
|
||||||
|
local secret_name="$1"
|
||||||
|
local secret_value
|
||||||
|
|
||||||
|
info "Fetching secret: $secret_name"
|
||||||
|
|
||||||
|
if ! secret_value=$(bw get password "$secret_name" --session "$BW_SESSION" 2>/dev/null); then
|
||||||
|
error "Failed to retrieve secret: $secret_name"
|
||||||
|
exit $ERR_SECRET_NOT_FOUND
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$secret_value" ]]; then
|
||||||
|
error "Secret '$secret_name' is empty or not found"
|
||||||
|
exit $ERR_SECRET_NOT_FOUND
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$secret_value"
|
||||||
|
}
|
||||||
|
|
||||||
|
list_secrets() {
|
||||||
|
info "Listing all available items..."
|
||||||
|
bw list items --session "$BW_SESSION" | jq -r '.[] | .name' 2>/dev/null || {
|
||||||
|
bw list items --session "$BW_SESSION" | grep '"name"' | cut -d'"' -f4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
$SCRIPT_DESC
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
$SCRIPT_NAME [OPTIONS] COMMAND [ARGS]
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
install Install Bitwarden CLI
|
||||||
|
get <secret_name> Retrieve a specific secret
|
||||||
|
list List all available secrets
|
||||||
|
test Test configuration and connectivity
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-c, --config FILE Use specific config file (default: $DEFAULT_CONFIG_FILE)
|
||||||
|
-h, --help Show this help message
|
||||||
|
-v, --version Show version information
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
$SCRIPT_NAME install
|
||||||
|
$SCRIPT_NAME get APIKEY-pushover
|
||||||
|
$SCRIPT_NAME list
|
||||||
|
$SCRIPT_NAME --config /path/to/config.conf get my-secret
|
||||||
|
|
||||||
|
Environment Variables (can be set in config file):
|
||||||
|
BW_SERVER_URL Bitwarden server URL
|
||||||
|
BW_CLIENTID API client ID
|
||||||
|
BW_CLIENTSECRET API client secret
|
||||||
|
BW_PASSWORD Master password
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
local config_file="$DEFAULT_CONFIG_FILE"
|
||||||
|
local command=""
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-c|--config)
|
||||||
|
config_file="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-v|--version)
|
||||||
|
echo "$SCRIPT_NAME version $SCRIPT_VERSION"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
install)
|
||||||
|
command="install"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
get)
|
||||||
|
command="get"
|
||||||
|
secret_name="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
command="list"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
test)
|
||||||
|
command="test"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error "Unknown option: $1"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
case "$command" in
|
||||||
|
install)
|
||||||
|
install_bitwarden_cli
|
||||||
|
;;
|
||||||
|
get)
|
||||||
|
if [[ -z "${secret_name:-}" ]]; then
|
||||||
|
error "Secret name required for 'get' command"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
load_config "$config_file"
|
||||||
|
install_bitwarden_cli
|
||||||
|
setup_bitwarden_server
|
||||||
|
login_and_unlock
|
||||||
|
fetch_secret "$secret_name"
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
load_config "$config_file"
|
||||||
|
install_bitwarden_cli
|
||||||
|
setup_bitwarden_server
|
||||||
|
login_and_unlock
|
||||||
|
list_secrets
|
||||||
|
;;
|
||||||
|
test)
|
||||||
|
load_config "$config_file"
|
||||||
|
install_bitwarden_cli
|
||||||
|
setup_bitwarden_server
|
||||||
|
login_and_unlock
|
||||||
|
info "Configuration test successful!"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error "No command specified"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup EXIT INT TERM
|
||||||
|
|
||||||
|
main "$@"
|
||||||
@@ -0,0 +1,495 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Test Suite for TSYS Secrets Manager
|
||||||
|
# Designed to work standalone and when vendored into shell scripting frameworks
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
# Determine script directory and main script location
|
||||||
|
readonly TEST_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
# Check if we're in the organized structure or vendored
|
||||||
|
if [[ -f "${TEST_SCRIPT_DIR}/../secrets-manager.sh" ]]; then
|
||||||
|
# Organized structure: tests/test-secrets-manager.sh
|
||||||
|
readonly SCRIPT_DIR="$(cd "${TEST_SCRIPT_DIR}/.." && pwd)"
|
||||||
|
readonly SECRETS_MANAGER="${SCRIPT_DIR}/secrets-manager.sh"
|
||||||
|
readonly TEST_CONFIG="${SCRIPT_DIR}/tests/test-bitwarden-config.conf"
|
||||||
|
else
|
||||||
|
# Vendored structure: all files in same directory
|
||||||
|
readonly SCRIPT_DIR="${TEST_SCRIPT_DIR}"
|
||||||
|
readonly SECRETS_MANAGER="${SCRIPT_DIR}/secrets-manager.sh"
|
||||||
|
readonly TEST_CONFIG="${SCRIPT_DIR}/test-bitwarden-config.conf"
|
||||||
|
fi
|
||||||
|
readonly TEST_LOG="/tmp/secrets-manager-test.log"
|
||||||
|
|
||||||
|
# Test framework variables
|
||||||
|
TESTS_RUN=0
|
||||||
|
TESTS_PASSED=0
|
||||||
|
TESTS_FAILED=0
|
||||||
|
TEST_FAILURES=()
|
||||||
|
|
||||||
|
# Colors for output (disabled in CI environments)
|
||||||
|
if [[ "${CI:-false}" == "true" ]] || [[ ! -t 1 ]]; then
|
||||||
|
RED=""
|
||||||
|
GREEN=""
|
||||||
|
YELLOW=""
|
||||||
|
BLUE=""
|
||||||
|
RESET=""
|
||||||
|
else
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
RESET='\033[0m'
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Logging functions
|
||||||
|
log_info() { echo -e "${BLUE}[INFO]${RESET} $*"; }
|
||||||
|
log_success() { echo -e "${GREEN}[PASS]${RESET} $*"; }
|
||||||
|
log_error() { echo -e "${RED}[FAIL]${RESET} $*"; }
|
||||||
|
log_warn() { echo -e "${YELLOW}[WARN]${RESET} $*"; }
|
||||||
|
|
||||||
|
# Test framework functions
|
||||||
|
setup_test_environment() {
|
||||||
|
log_info "Setting up test environment..."
|
||||||
|
|
||||||
|
# Ensure secrets-manager.sh exists and is executable
|
||||||
|
if [[ ! -f "$SECRETS_MANAGER" ]]; then
|
||||||
|
log_error "secrets-manager.sh not found at $SECRETS_MANAGER"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -x "$SECRETS_MANAGER" ]]; then
|
||||||
|
chmod +x "$SECRETS_MANAGER"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create test config file
|
||||||
|
create_test_config
|
||||||
|
|
||||||
|
# Clear test log
|
||||||
|
> "$TEST_LOG"
|
||||||
|
|
||||||
|
log_info "Test environment ready"
|
||||||
|
}
|
||||||
|
|
||||||
|
create_test_config() {
|
||||||
|
cat > "$TEST_CONFIG" <<EOF
|
||||||
|
# Test configuration for secrets manager
|
||||||
|
BW_SERVER_URL="https://test.bitwarden.com"
|
||||||
|
BW_CLIENTID="test_client_id"
|
||||||
|
BW_CLIENTSECRET="test_client_secret"
|
||||||
|
BW_PASSWORD="test_password"
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_test_environment() {
|
||||||
|
log_info "Cleaning up test environment..."
|
||||||
|
|
||||||
|
# Remove test config
|
||||||
|
[[ -f "$TEST_CONFIG" ]] && rm -f "$TEST_CONFIG"
|
||||||
|
|
||||||
|
# Remove test log
|
||||||
|
[[ -f "$TEST_LOG" ]] && rm -f "$TEST_LOG"
|
||||||
|
|
||||||
|
# Clear any Bitwarden session
|
||||||
|
unset BW_SESSION 2>/dev/null || true
|
||||||
|
|
||||||
|
log_info "Cleanup complete"
|
||||||
|
}
|
||||||
|
|
||||||
|
run_test() {
|
||||||
|
local test_name="$1"
|
||||||
|
local test_function="$2"
|
||||||
|
|
||||||
|
((TESTS_RUN++))
|
||||||
|
log_info "Running test: $test_name"
|
||||||
|
|
||||||
|
if $test_function; then
|
||||||
|
((TESTS_PASSED++))
|
||||||
|
log_success "$test_name"
|
||||||
|
else
|
||||||
|
((TESTS_FAILED++))
|
||||||
|
TEST_FAILURES+=("$test_name")
|
||||||
|
log_error "$test_name"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_equals() {
|
||||||
|
local expected="$1"
|
||||||
|
local actual="$2"
|
||||||
|
local message="${3:-}"
|
||||||
|
|
||||||
|
if [[ "$expected" == "$actual" ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
[[ -n "$message" ]] && log_error "$message"
|
||||||
|
log_error "Expected: '$expected', Got: '$actual'"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_contains() {
|
||||||
|
local haystack="$1"
|
||||||
|
local needle="$2"
|
||||||
|
local message="${3:-}"
|
||||||
|
|
||||||
|
if [[ "$haystack" == *"$needle"* ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
[[ -n "$message" ]] && log_error "$message"
|
||||||
|
log_error "Expected '$haystack' to contain '$needle'"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_file_exists() {
|
||||||
|
local file_path="$1"
|
||||||
|
local message="${2:-}"
|
||||||
|
|
||||||
|
if [[ -f "$file_path" ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
[[ -n "$message" ]] && log_error "$message"
|
||||||
|
log_error "File does not exist: $file_path"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_command_success() {
|
||||||
|
local command="$1"
|
||||||
|
local message="${2:-}"
|
||||||
|
|
||||||
|
if eval "$command" >/dev/null 2>&1; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
[[ -n "$message" ]] && log_error "$message"
|
||||||
|
log_error "Command failed: $command"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_command_failure() {
|
||||||
|
local command="$1"
|
||||||
|
local message="${2:-}"
|
||||||
|
|
||||||
|
if ! eval "$command" >/dev/null 2>&1; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
[[ -n "$message" ]] && log_error "$message"
|
||||||
|
log_error "Command unexpectedly succeeded: $command"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test cases
|
||||||
|
test_script_exists_and_executable() {
|
||||||
|
assert_file_exists "$SECRETS_MANAGER" "secrets-manager.sh should exist" &&
|
||||||
|
assert_command_success "[[ -x '$SECRETS_MANAGER' ]]" "secrets-manager.sh should be executable"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_help_option() {
|
||||||
|
local output
|
||||||
|
output=$("$SECRETS_MANAGER" --help 2>&1) &&
|
||||||
|
assert_contains "$output" "TSYS Secrets Manager" "Help should contain project name" &&
|
||||||
|
assert_contains "$output" "Usage:" "Help should contain usage information"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_version_option() {
|
||||||
|
local output
|
||||||
|
output=$("$SECRETS_MANAGER" --version 2>&1) &&
|
||||||
|
assert_contains "$output" "version" "Version output should contain 'version'"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_config_file_validation() {
|
||||||
|
# Test with non-existent config file
|
||||||
|
assert_command_failure "'$SECRETS_MANAGER' --config /nonexistent/config.conf test" \
|
||||||
|
"Should fail with non-existent config file"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_config_file_loading() {
|
||||||
|
# Test with valid test config
|
||||||
|
local output
|
||||||
|
output=$("$SECRETS_MANAGER" --config "$TEST_CONFIG" test 2>&1 || true) &&
|
||||||
|
assert_contains "$output" "Loading configuration" "Should attempt to load config file"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_install_command_structure() {
|
||||||
|
# Test install command without actually installing
|
||||||
|
local output
|
||||||
|
output=$("$SECRETS_MANAGER" install 2>&1 || true) &&
|
||||||
|
assert_contains "$output" "Bitwarden CLI" "Install command should mention Bitwarden CLI"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_missing_command_error() {
|
||||||
|
local output
|
||||||
|
output=$("$SECRETS_MANAGER" 2>&1 || true) &&
|
||||||
|
assert_contains "$output" "No command specified" "Should show error for missing command"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_invalid_command_error() {
|
||||||
|
local output
|
||||||
|
output=$("$SECRETS_MANAGER" invalidcommand 2>&1 || true) &&
|
||||||
|
assert_contains "$output" "Unknown option" "Should show error for invalid command"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_get_command_requires_secret_name() {
|
||||||
|
local output
|
||||||
|
output=$("$SECRETS_MANAGER" get 2>&1 || true) &&
|
||||||
|
assert_contains "$output" "Secret name required" "Get command should require secret name"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_script_error_codes() {
|
||||||
|
# Test that script uses proper exit codes
|
||||||
|
local exit_code
|
||||||
|
|
||||||
|
# Test invalid command
|
||||||
|
"$SECRETS_MANAGER" invalidcommand >/dev/null 2>&1 || exit_code=$?
|
||||||
|
assert_equals "1" "$exit_code" "Invalid command should exit with code 1"
|
||||||
|
|
||||||
|
# Test missing config file
|
||||||
|
"$SECRETS_MANAGER" --config /nonexistent/config.conf test >/dev/null 2>&1 || exit_code=$?
|
||||||
|
assert_equals "10" "$exit_code" "Missing config should exit with code 10"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_logging_functionality() {
|
||||||
|
# Run a command that should generate logs
|
||||||
|
"$SECRETS_MANAGER" --help >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Check if log file is created (script creates logs for most operations)
|
||||||
|
if [[ -f "$TEST_LOG" ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# Some operations might not create logs, so this is a soft test
|
||||||
|
log_warn "Log file not created - this may be normal for help command"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
test_cleanup_functionality() {
|
||||||
|
# Test that cleanup doesn't crash
|
||||||
|
assert_command_success "unset BW_SESSION 2>/dev/null || true" \
|
||||||
|
"Cleanup should handle missing session gracefully"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_config_file_security() {
|
||||||
|
# Ensure test config file has appropriate permissions
|
||||||
|
local perms
|
||||||
|
perms=$(stat -c "%a" "$TEST_CONFIG" 2>/dev/null || echo "644")
|
||||||
|
|
||||||
|
# Config file should be readable by owner (we created it, so this should pass)
|
||||||
|
if [[ "$perms" =~ ^[67][0-7][0-7]$ ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
log_warn "Config file permissions: $perms (consider restricting to 600)"
|
||||||
|
return 0 # Don't fail test, just warn
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
test_bitwarden_dependency_check() {
|
||||||
|
local output
|
||||||
|
# Test without Bitwarden CLI installed (if not already installed)
|
||||||
|
if ! command -v bw >/dev/null 2>&1; then
|
||||||
|
output=$(timeout 10 "$SECRETS_MANAGER" --config "$TEST_CONFIG" test 2>&1 || true)
|
||||||
|
assert_contains "$output" "not installed" "Should detect missing Bitwarden CLI"
|
||||||
|
else
|
||||||
|
log_info "Bitwarden CLI already installed - skipping dependency check test"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Integration tests (require actual Bitwarden setup)
|
||||||
|
test_integration_bitwarden_config() {
|
||||||
|
# Only run if we have a real config file
|
||||||
|
if [[ -f "${SCRIPT_DIR}/bitwarden-config.conf" ]]; then
|
||||||
|
log_info "Found real config file - running integration test"
|
||||||
|
local output
|
||||||
|
output=$(timeout 10 "$SECRETS_MANAGER" test 2>&1 || true)
|
||||||
|
# Don't assert success since we may not have valid credentials
|
||||||
|
# Just check that it attempts the operation
|
||||||
|
assert_contains "$output" "Bitwarden" "Should attempt Bitwarden operations"
|
||||||
|
else
|
||||||
|
log_info "No real config file found - skipping integration test"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Performance tests
|
||||||
|
test_script_startup_time() {
|
||||||
|
local start_time end_time duration
|
||||||
|
start_time=$(date +%s%N)
|
||||||
|
"$SECRETS_MANAGER" --help >/dev/null 2>&1
|
||||||
|
end_time=$(date +%s%N)
|
||||||
|
duration=$(( (end_time - start_time) / 1000000 )) # Convert to milliseconds
|
||||||
|
|
||||||
|
# Script should start in reasonable time (less than 5 seconds)
|
||||||
|
if [[ $duration -lt 5000 ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
log_warn "Script startup took ${duration}ms (expected < 5000ms)"
|
||||||
|
return 0 # Don't fail, just warn
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Vendor integration tests
|
||||||
|
test_vendor_compatibility() {
|
||||||
|
# Test that script works when called from different directories
|
||||||
|
local temp_dir
|
||||||
|
temp_dir=$(mktemp -d)
|
||||||
|
|
||||||
|
pushd "$temp_dir" >/dev/null
|
||||||
|
local output
|
||||||
|
output=$("$SECRETS_MANAGER" --help 2>&1)
|
||||||
|
popd >/dev/null
|
||||||
|
|
||||||
|
rmdir "$temp_dir"
|
||||||
|
|
||||||
|
assert_contains "$output" "TSYS Secrets Manager" \
|
||||||
|
"Script should work when called from different directory"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main test runner
|
||||||
|
run_all_tests() {
|
||||||
|
log_info "Starting TSYS Secrets Manager Test Suite"
|
||||||
|
echo "========================================"
|
||||||
|
|
||||||
|
setup_test_environment
|
||||||
|
|
||||||
|
# Basic functionality tests
|
||||||
|
run_test "Script exists and is executable" test_script_exists_and_executable
|
||||||
|
run_test "Help option works" test_help_option
|
||||||
|
run_test "Version option works" test_version_option
|
||||||
|
run_test "Config file validation" test_config_file_validation
|
||||||
|
run_test "Config file loading" test_config_file_loading
|
||||||
|
run_test "Install command structure" test_install_command_structure
|
||||||
|
run_test "Missing command error" test_missing_command_error
|
||||||
|
run_test "Invalid command error" test_invalid_command_error
|
||||||
|
run_test "Get command validation" test_get_command_requires_secret_name
|
||||||
|
run_test "Script error codes" test_script_error_codes
|
||||||
|
run_test "Logging functionality" test_logging_functionality
|
||||||
|
run_test "Cleanup functionality" test_cleanup_functionality
|
||||||
|
run_test "Config file security" test_config_file_security
|
||||||
|
run_test "Bitwarden dependency check" test_bitwarden_dependency_check
|
||||||
|
|
||||||
|
# Integration tests
|
||||||
|
run_test "Integration: Bitwarden config" test_integration_bitwarden_config
|
||||||
|
|
||||||
|
# Performance tests
|
||||||
|
run_test "Script startup time" test_script_startup_time
|
||||||
|
|
||||||
|
# Vendor compatibility tests
|
||||||
|
run_test "Vendor compatibility" test_vendor_compatibility
|
||||||
|
|
||||||
|
cleanup_test_environment
|
||||||
|
|
||||||
|
# Print results
|
||||||
|
echo "========================================"
|
||||||
|
log_info "Test Results:"
|
||||||
|
echo " Total tests run: $TESTS_RUN"
|
||||||
|
echo " Tests passed: $TESTS_PASSED"
|
||||||
|
echo " Tests failed: $TESTS_FAILED"
|
||||||
|
|
||||||
|
if [[ $TESTS_FAILED -gt 0 ]]; then
|
||||||
|
echo ""
|
||||||
|
log_error "Failed tests:"
|
||||||
|
for failure in "${TEST_FAILURES[@]}"; do
|
||||||
|
echo " - $failure"
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
log_success "All tests passed!"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Command line interface
|
||||||
|
show_usage() {
|
||||||
|
cat <<EOF
|
||||||
|
TSYS Secrets Manager Test Suite
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
$0 [OPTIONS] [COMMAND]
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
run Run all tests (default)
|
||||||
|
setup Setup test environment only
|
||||||
|
cleanup Cleanup test environment only
|
||||||
|
list List available test functions
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help Show this help message
|
||||||
|
-v, --verbose Enable verbose output
|
||||||
|
--ci Run in CI mode (no colors)
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
$0 # Run all tests
|
||||||
|
$0 run # Run all tests
|
||||||
|
$0 setup # Setup test environment
|
||||||
|
$0 cleanup # Cleanup test files
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
list_tests() {
|
||||||
|
echo "Available test functions:"
|
||||||
|
declare -F | grep "test_" | sed 's/declare -f / - /'
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
local command="run"
|
||||||
|
local verbose=false
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-h|--help)
|
||||||
|
show_usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-v|--verbose)
|
||||||
|
set -x
|
||||||
|
verbose=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--ci)
|
||||||
|
CI=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
run|setup|cleanup|list)
|
||||||
|
command="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: $1"
|
||||||
|
show_usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
case "$command" in
|
||||||
|
run)
|
||||||
|
run_all_tests
|
||||||
|
;;
|
||||||
|
setup)
|
||||||
|
setup_test_environment
|
||||||
|
;;
|
||||||
|
cleanup)
|
||||||
|
cleanup_test_environment
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
list_tests
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown command: $command"
|
||||||
|
show_usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Handle script being sourced vs executed
|
||||||
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||||
|
main "$@"
|
||||||
|
fi
|
||||||
@@ -41,7 +41,7 @@ TODAY="$(date +%Y-%m-%d)"
|
|||||||
# Runs in Docker so the host stays clean (no native shellcheck required).
|
# Runs in Docker so the host stays clean (no native shellcheck required).
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
$RULE_VERBOSE && log_step "Shell scripts (shellcheck)"
|
$RULE_VERBOSE && log_step "Shell scripts (shellcheck)"
|
||||||
mapfile -d '' SH_FILES < <(find . -path ./.git -prune -o -path ./.tmp -prune -o -path ./.crush -prune -o -path ./vendor -prune -o -path ./oam/librenms-agent/agent -prune -o -path ./archive -prune -o -path ./node_modules -prune -o \( -name '*.sh' -o -name '*.bash' \) -print0 2>/dev/null)
|
mapfile -d '' SH_FILES < <(find . -path ./.git -prune -o -path ./.tmp -prune -o -path ./.crush -prune -o -path ./vendor -prune -o -path ./oam/librenms-agent/agent -prune -o -path ./archive -prune -o -path ./node_modules -prune -o -path ./legacy-knelsecretsmanager -prune -o \( -name '*.sh' -o -name '*.bash' \) -print0 2>/dev/null)
|
||||||
if [ "${#SH_FILES[@]}" -gt 0 ]; then
|
if [ "${#SH_FILES[@]}" -gt 0 ]; then
|
||||||
if have shellcheck; then
|
if have shellcheck; then
|
||||||
if shellcheck "${SH_FILES[@]}" >/dev/null 2>&1; then
|
if shellcheck "${SH_FILES[@]}" >/dev/null 2>&1; then
|
||||||
@@ -163,7 +163,7 @@ while IFS= read -r -d '' f; do
|
|||||||
POINTER_MISSING=$((POINTER_MISSING + 1))
|
POINTER_MISSING=$((POINTER_MISSING + 1))
|
||||||
$RULE_VERBOSE && printf ' %s\n' "$f"
|
$RULE_VERBOSE && printf ' %s\n' "$f"
|
||||||
fi
|
fi
|
||||||
done < <(find . -path ./.git -prune -o -path ./.crush -prune -o -path ./.tmp -prune -o -path ./vendor -prune -o -path ./archive -prune -o -name '*.md' -print0 2>/dev/null)
|
done < <(find . -path ./.git -prune -o -path ./.crush -prune -o -path ./.tmp -prune -o -path ./vendor -prune -o -path ./archive -prune -o -path "./legacy-*" -prune -o -name "*.md" -print0 2>/dev/null)
|
||||||
if [ "$POINTER_MISSING" -eq 0 ]; then
|
if [ "$POINTER_MISSING" -eq 0 ]; then
|
||||||
check "All non-exempt .md cite Discourse ($DISCOURSE_HOST)" "pass"
|
check "All non-exempt .md cite Discourse ($DISCOURSE_HOST)" "pass"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user