Blender Constraint : Slide Link
In my example the bigger cylinder is parent of the small one,and it's rotated 45 degrees on its Y axis. The small one has X and Y loc locked, so it can only slide on its Z local location. The same can be achieved with bones, locking their local attributes.